为了让用户可以为一个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
评论
代碼修改
$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))
------------------------------------------------------------------------------------------------------------------------
第一个是对的,应该为'annotate_node_type
第一个是对的,应该为'annotate_node_types',
第2个,我不知道TRUE这个参数是不是必须的,这是一个PHP函数的参数了,加上应该也是对的,
第二个应该加上
if('zhangsan' == 0) {
echo 'OK';
}else {
echo 'NO';
}
结果是 : OK
所以要加上,不然设置那里就没有用了
明白了^_^
明白了^_^
zhupou man这么亲切的名字啊
zhupou man这么亲切的名字啊