You are here

18 为函数编写文档

admin 的头像
Submitted by admin on 星期五, 2015-09-18 08:56

作者:老葛,北京亚艾元软件有限责任公司,http://www.yaiyuan.com

函数文档应该使用下面的语法:

 

/**

 * Extract the type name.

 *

 * @param $node

 *   Either a string or object, containing the node type information.

 *

 * @return

 *   Node type of the passed-in data.

 */

function _node_extract_type($node) {

  return is_object($node) ? $node->type : $node;

}

    在文档的开头,我们首先描述一下这个函数是用来做什么的。如果你是用英语写文档的话,注意这里使用祈使语句。

 

    这里我们用到了两个文档指令, @param用来给出函数的参数,一个函数文档可以包含多个@param@return用来表示函数的返回值,通常只有一个。

   此外,我们还会用到其它一些文档指令,比如@ingroup

/**

 * Saves a node.

 *

 * @ingroup actions

 */

function node_save_action($node) {

  …

}

    它可以将一组函数关联在一起。node.module中有多个函数用到了@ingroup actions

/**

 * Sets the promote property of a node to 0.

 *

 * @ingroup actions

 */

function node_unpromote_action($node, $context = array()) {

  …

}

    在http://api.drupal.org/api/drupal/includes--actions.inc/group/actions/7里面,我们可以查看actions组所包含的所有函数。

    node.module里面所包含的文档指令,并不止这些,我们在这里就不逐一加以说明了。

 

    对于页面回调函数,我们应该注明它是页面回调,并给出函数的简单说明。

 

/**

 * Menu callback -- ask for confirmation of node deletion

 */

function node_delete_confirm($form, &$form_state, $node) {

  …

}


Drupal版本: