有人可以提供 Drupal 7 控制流的架构概述吗?也许在关于如何生成页面的流程图的意义上.关于 Drupal 的工作原理,您建议咨询哪些其他资源?
Could someone provide a architectural overview of the Drupal 7 control flow? Perhaps in the sense of a flowchart about how a page gets generated. What additional resources would you suggest consulting with regards to how Drupal works?
Drupal 在这方面可能会令人困惑,部分原因是它具有相对较深的函数堆栈.尽管它是过程式 PHP,但它在其体系结构中纯粹是事件/侦听器驱动的,并且在主要的 PHP 脚本中没有简单的流程"供您查看.我最近做了关于这个主题的演示,幻灯片发布在slideshare上,但是一个快速的高层次总结可能会有用.
Drupal can be confusing on this front, partially because it has a relatively deep function stack. Although it's procedural PHP it's purely event/listener driven in its architecture, and there's no simple "flow" in the main PHP script for you to look though. I recently did a presentation on this very subject, and the slides are posted on slideshare, but a quick high-level summary may be useful.
在整个过程中,Drupal 和第三方插件模块会触发事件,并监听它们的响应.Drupal 称其为钩子"系统,它是使用函数命名约定实现的.例如,博客"模块可以通过实现一个名为 blog_user() 的函数来拦截用户"相关的信息.在 Drupal 中,这称为 hook_user().
During that entire process, Drupal and third-party plugin modules are firing off events, and listening for them to respond. Drupal calls this the 'hook' system, and it's implemented using function naming conventions. The 'blog' module, for example, can intercept 'user' related by implementing a function named blog_user(). In Drupal parlance, that's called hook_user().
它有点笨拙,但由于 PHP 的一个怪癖(它保留了所有加载函数的内部哈希表),它允许 Drupal 只需遍历已安装插件的列表即可快速检查侦听器.对于每个插件,它可以在适当命名的模式上调用 function_exists(),如果存在则调用该函数.(我正在触发 'login' 事件.'mymodule_login' 函数是否存在?我会调用它.'yourmodule_login' 是否存在?不?'nextmodule_login' 怎么样?"等等)再次,有点笨重,但它效果很好.
It's a bit clunky, but due to a PHP quirk (it keeps an internal hashtable of all loaded functions), it allows Drupal to quickly check for listeners just by iterating over a list of installed plugins. For each plugin it can call function_exists() on the appropriately named pattern, and call the function if it exists. ("I'm firing the 'login' event. Does 'mymodule_login' function exist? I'll call it. Does 'yourmodule_login' exist? No? How about 'nextmodule_login'?" etc.) Again, a touch clunky but it works pretty well.
在 Drupal 中发生的一切都是因为其中一个事件被触发.MenuAPI 只知道不同插件模块处理哪些 url/路径,因为它会触发菜单"事件 (hook_menu) 并收集所有元数据插件模块响应.(我会处理 url 'news/recent',这里是需要构建该页面时调用的函数......")内容只会被保存,因为 Drupal 的 FormAPI 负责构建一个页面,并触发模块响应的表单已提交"事件.每小时维护是因为 hook_cron() 被触发,任何以 mymodulename_cron() 作为函数名的模块都会调用它的函数.
Everything that happens in Drupal happens because of one of those events being fired. The MenuAPI only knows about what urls/paths are handled by different plugin modules because it fires the 'menu' event (hook_menu) and gathers up all the metadata plugin modules respond with. ("I'll take care of the url 'news/recent', and here's the function to call when that page needs to be built...") Content only gets saved because Drupal's FormAPI is responsible for building a page, and fires the 'a form was submitted' event for a module to respond to. Hourly maintenance happens because hook_cron() is triggered, and any module with mymodulename_cron() as a function name will have its function called.
其他一切最终都只是细节——重要的细节,但该主题的变化.index.php 是控制器,菜单系统确定当前页面"是什么,并且在构建该页面的过程中会触发许多事件.插件模块可以挂钩这些事件并更改工作流程/提供附加信息等.这也是如此多的 Drupal 资源专注于制作模块的部分原因.没有模块,Drupal 除了说,'有人要求一个页面!它存在吗?不?好的,我会提供 404.'
Everything else is ultimately just details -- important details, but variations on that theme. index.php is the controller, the menu system determins what the "current page" is, and lots of events get fired in the process of building that page. Plugin modules can hook into those events and change the workflow/supply additional information/etc. That's also part of the reason so many Drupal resources focus on making modules. Without modules, Drupal doesn't actually DO anything other than say, 'Someone asked for a page! Does it exist? No? OK, I'll serve up a 404.'
这篇关于Drupal 是如何工作的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!