27
十/080
十/080
drupal动态菜单的一点心得
drupal的菜单系统,可以设置是否缓存菜单项,这个是通过$may_cache参数进行设置的。一般的drupal应用大部分都可以设置为静态菜单,也就是$may_cache为true的情况,但有些时候我们可以用动态菜单实现。
比如要我们要编辑一个内容,对应的path地址是’example/edit/’. $id,这个地址映射到函数example_edit_form,我们向这个表单传递一个id参数,这时候可以写:
if ($may_cache) {
// nothing.
}
else {
if (’example’ == arg(0) && ‘edit’ == arg(1) && is_numeric(arg(2)) {
$items[] = array(
‘path’ => ‘example/edit’,
‘callback’ => ‘drupal_get_form’,
‘callback arguments’ => array(’example_edit_form’, arg(2)),
‘access’ => true, // 调整为具体权限。
);
}
}
这样只要在表单定义函数中,应用获得的id参数给default_value指定默认值就可以了。