You are here

添加数据输入表单(1)

g089h515r806 的头像
Submitted by g089h515r806 on 星期二, 2009-07-28 12:17

为了让用户可以为一个web页面输入笔记,我们需要为它提供一个地方,专门用来输入笔记。下面我们在annotate.module中为笔记添加一个表单:

    (译者注:这里的笔记就是注释的意思)
 
/**
* Implementation of hook_nodeapi().
*/
function annotate_nodeapi(&$node, $op, $teaser, $page) {
    global $user;
    switch ($op) {
        // The 'view' operation means the node is about to be displayed.
        case 'view':
            // Abort if the user is an anonymous user (not logged in) or
            // if the node is not being displayed on a page by itself
            // (for example, it could be in a node listing or search result).
            if ($user->uid == 0 || !$page) {
                break;
            }
            // Find out which node types we should annotate.
            $types_to_annotate = variable_get('annotate_nodetypes', array('page'));
            // Abort if this node is not one of the types we should annotate.
            if (!in_array($node->type, $types_to_annotate)) {
                break;
            }
 
            // Add our form as a content item.
            $node->content['annotation_form'] = array(
                '#value' => drupal_get_form('annotate_entry_form', $node),
                '#weight' => 10
            );
            break;
    }
}

老葛的Drupal培训班 Think in Drupal

Drupal版本:

评论

thomasfan 的头像

$types_to_annotate = variable_get('annotate_nodetypes', array('page'));

修改为

$types_to_annotate = variable_get('annotate_node_types', array('page'));

----------------------------------------------------------------------------------------------------------------------

if (!in_array($node->type, $types_to_annotate))

修改为

if (!in_array($node->type, $types_to_annotate,TRUE))

------------------------------------------------------------------------------------------------------------------------

zhupouMan 的头像

if('zhangsan' == 0) {

   echo 'OK';

}else {

   echo 'NO';

}

 

结果是 : OK

所以要加上,不然设置那里就没有用了