跳转到主要内容
dororo80 提交于 19 April 2013

在书中看到:

You defined permissions in hook_permission(), but how are they enforced? Node modules can limit access to the node types they define using hook_node_access() . The superuser (user ID 1) will always bypass any access check, so this hook isn’t called in that case. If this hook is n’t defined for your node type, all access checks will fail, so only the superuser and those with “administer nodes” permissions will be able to create, edit, or delete content of that type. 自己翻译如下:

如果定义了hook_permission(),但怎么实施的?Node module能通过定义hook_node_access(),对node类型限制访问.超级管理员ID1可以进行任何访问,所以这个hook_node_access()在这个例子里不会被调用。如果这个hook_node_access()没有定义你的node类型,所有的访问都会失败,所以只有超级管理员和那些有node管理权限的可以创建、编辑、删除这个类型的内容。  

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

最后一句话弄得我一头雾水。我创建了一个node类型,定义了hook_permission(),把permission给了超级管理员和授权role。然后他们都可以创建、编辑这些了。并没有定义hook_node_access()。也达到效果了啊?到底除了hook­_permission()要不要写hook_node_access()呢?  

Drupal 版本