drupal是modules组成的一个架构。功能被包含在modules里面,能运用也可以被禁用。
drupal反向控制设计模式,在适当的时间,modular功能被架构调用。同时modules开始工作,也被叫做hooks——勾住。
hooks可以被看作是drupal内部的事件。但是又有些不同与事件。
比如,一个用户登陆,drupal激活 hook_user_login,同时其他相关modules中的按照命名规则,以_user_login结尾的程序都要被调用。比如 comment module 里面的comment_user_login;node module里面的node_user_login;等等。
http://api.drupal.org/api/7 《官方文档》
在篇文档里面说的更加清楚,
Drupal's module system is based on the concept of "hooks". A hook is a PHP function that is named foo_bar(), where "foo" is the name of the module (whose filename is thus foo.module) and "bar" is the name of the hook. Each hook has a defined set of parameters and a specified result type.
To extend Drupal, a module need simply implement a hook. When Drupal wishes to allow intervention from modules, it determines which modules implement a hook and calls that hook in all enabled modules that implement it.
The available hooks to implement are explained here in the Hooks section of the developer documentation. The string "hook" is used as a placeholder for the module name in the hook definitions. For example, if the module file is called example.module, then hook_help() as implemented by that module would be defined as example_help().
The example functions included are not part of the Drupal core, they are just models that you can modify. Only the hooks implemented within modules are executed when running Drupal.
drupal的modules系统是基于“hooks”的理念。一个hook是一个php程序,被命名为 foo_bar(),foo就是module的名字,文件名就叫做foo.module.而bar是钩子的名字。每个钩子都有定义配套参数和特殊的返回结果类型。
向drupal延伸,一个module需要简单的执行一个钩子。当drupal希望允许介入modules,他要决定那个modules执行一个钩子,并在所有可用的modules里面调用和执行它。
“hook”这个字符串就像一个占位符。当有一个example.module,当执行hook_help(),对这个module来说就是被定义的example_help()程序。
本文介绍了Drupal的内容管理系统中模块和Hooks的工作原理。Drupal通过模块化的架构实现功能的扩展与禁用,而Hooks作为核心机制之一,允许开发者在特定时刻插入自定义行为。
814

被折叠的 条评论
为什么被折叠?



