Drupal如何工作? [英] How Drupal works?

查看:99
本文介绍了Drupal如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以提供Drupal 7控制流程的架构概述吗?也许是关于如何生成页面的流程图。你会建议哪些额外的资源咨询Drupal如何工作?

解决方案

Drupal在这方面可能会令人困惑,部分原因是具有相对较深的功能堆栈。虽然它是程序PHP,它是纯粹的事件/监听器驱动的架构,并没有简单的流在主要PHP脚本,你看看。我最近做了关于这个主题的演示,幻灯片发布在幻灯片上,但是快速的高级摘要可能很有用。




  • Drupal的index.php文件用作前端控制器。所有页面都通过它管道,用户请求的实际url /路径作为参数传递给index.php。

  • Drupal的路径路由器系统(MenuAPI)用于匹配给定插件模块的请求路径。该插件模块负责构建页面的主要内容。

  • 一旦创建了主页面内容,index.php将调用主题(page,$ content),其中将内容交给Drupal的主题/皮肤系统。在那里,它包裹在sidebars / headers / widgets / etc ..

  • 然后将渲染的页面传回给apache,并将其发送回用户的浏览器。



在整个过程中,Drupal和第三方插件模块正在关闭事件,并监听它们以进行响应。 Drupal称之为挂钩系统,它使用函数命名约定来实现。例如,'blog'模块可以通过实现名为blog_user()的函数拦截相关的'user'。在Drupal的说法中,这被称为

  • hook_user()。



    这有点笨拙,但是由于PHP的怪癖(它保留了内部的哈希表所有加载的功能),它允许Drupal通过遍历已安装的插件列表快速检查监听器。对于每个插件,它可以在适当命名的模式上调用function_exists(),并调用函数(如果存在)。 (我正在启动登录事件,'mymodule_login'函数是否存在?我会调用它,'yourmodule_login'是否存在?否?'nextmodule_login'?等等)再次,触摸笨拙但是工作相当不错。



    发生在Drupal中的一切是因为其中一个事件被触发。 MenuAPI只知道不同插件模块处理的URL /路径,因为它触发'菜单'事件(hook_menu)并收集所有的元数据插件模块响应。 (我会照顾url的消息/最近的消息,这里是需要编译的页面时调用的函数...)内容只能被保存,因为Drupal的FormAPI负责构建一个页面,并且触发提交的一个表单被提交的一个模块来响应。小时维护发生是因为hook_cron()被触发,并且具有mymodulename_cron()作为函数名称的任何模块都将具有调用其功能。



    其他一切都是最终只是细节 - 重要的细节,但这个主题的变化。 index.php是控制器,菜单系统确定当前页面是什么,并且在构建该页面的过程中会触发很多事件。插件模块可以挂接到这些事件中,并更改工作流/提供附加信息等。这也是许多Drupal资源专注于制作模块的原因之一。没有模块,Drupal实际上并没有做任何事情,除了说,有人要求一个页面!是否存在?没有?好的,我会提供一个404。


    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 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's index.php file functions as a frontside controller. All page are piped through it, and the "actual" url/path the user requested is passed to index.php as a parameter.
    • Drupal's path router system (MenuAPI) is used to match the requested path to a given plugin module. That plugin module is responsible for building the "primary content" of the page.
    • Once the primary page content is built, index.php calls theme('page', $content), which hands off the content to Drupal's theming/skinning system. There, it's wrapped in sidebars/headers/widgets/etc..
    • The rendered page is then handed back to apache and it gets sent back to the user's browser.

    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().

    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.

    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.

    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如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆