How Drupal servers requests?
来源:互联网 发布:微信网络答题系统 编辑:程序博客网 时间:2024/05/21 22:28
Any request to Drupal page is served by the index.phpfile in Drupal's directory.
The content of the index.php is very simple:
define(
'DRUPAL_ROOT'
,
getcwd
());
require_once
DRUPAL_ROOT .
'/includes/bootstrap.inc'
;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
menu_execute_active_handler();
includes/bootstrap.incdefines several constants and contains thedrupal_bootstrap function - this function executes bootstrapsteps one by one and ent up with the all the basic Drupalstructures initialized and ready to use. Here is the list ofimportant Drupal global variables, available afterbootstrapping:
- base_url,base_path, base_root
- string variables with information about Drupal host URL
- databases
- array with connection settings to databases
- conf
- array of persistent variables, initialized by the Drupalsystem, modules, themes, etc.
- user
- array with information about currently logged used
The menu_execute_active_handler function executes handler,associated with the path, specified in the request URL, but does itonly when the site is not in the maintenance mode(variable_get('maintenance_mode', 0)
) or current userhas "access site in maintenance mode" permission(user_access('access site in maintenance mode')
).
The menu_execute_active_handler calls the menu_get_item function to get the menu item that should beprocessed. Then it checks whether the currently logged user canaccess the item, includes associated file (if it is required),executes callback function and delivers content to the user.
The variables that affect routing:
- $conf['maintenance_mode']
- Value "1" indicates that site is in the maintenance mode.
- $conf['site_frontpage']
- Menu item that should be processed when the site front page isrequested. Default value: node. Hardcoded indrupal_path_initialize.
- $_GET['q']
- Path of the menu item, which handler will be executed.
- drupal_static('menu_get_item')
- Loaded menu items, the current item isdrupal_static('menu_get_item')[$_GET['q']].
For example, request to the default page is processed asfollows:
- During bootstrapping (in the drupal_bootstrap function) the _drupal_bootstrap_configuration function initializes $_GET['q']with the current path by callingdrupal_environment_initialize and then _drupal_bootstrap_full rewrites $_GET['q'] by calling drupal_path_initialize.
- Then menu_execute_active_handler checks the maintenance mode flag,requests menu item by calling themenu_get_item function, check user permissions and executes thenode_page_default callback function.
Menu routes are stored in the menu_router table in thedatabase:
mysql> desc menu_router;+-------------------+--------------+------+-----+---------+-------+| Field | Type | Null | Key | Default | Extra |+-------------------+--------------+------+-----+---------+-------+| path | varchar(255) | NO | PRI | | || load_functions | blob | NO | | NULL | || to_arg_functions | blob | NO | | NULL | || access_callback | varchar(255) | NO | | | || access_arguments | blob | YES | | NULL | || page_callback | varchar(255) | NO | | | || page_arguments | blob | YES | | NULL | || delivery_callback | varchar(255) | NO | | | || fit | int(11) | NO | MUL | 0 | || number_parts | smallint(6) | NO | | 0 | || context | int(11) | NO | | 0 | || tab_parent | varchar(255) | NO | MUL | | || tab_root | varchar(255) | NO | MUL | | || title | varchar(255) | NO | | | || title_callback | varchar(255) | NO | | | || title_arguments | varchar(255) | NO | | | || theme_callback | varchar(255) | NO | | | || theme_arguments | varchar(255) | NO | | | || type | int(11) | NO | | 0 | || description | text | NO | | NULL | || position | varchar(255) | NO | | | || weight | int(11) | NO | | 0 | || include_file | mediumtext | YES | | NULL | |+-------------------+--------------+------+-----+---------+-------+23 rows in set (0.00 sec)
So, there is two methods to get the page_callback value for thegiven path:
- Inject debugging code into the menu_execute_active_handler function and print
$router_item['include_file']
,$router_item['page_callback']
and$router_item['page_arguments']
. - Query the database:
select path, include_file,page_callback, page_arguments from menu_router
. The querycan be refined with the WHERE statement.
Example:
mysql> select path, include_file, page_callback from menu_router -> where path='admin/config';+--------------+---------------------------------+--------------------------+| path | include_file | page_callback |+--------------+---------------------------------+--------------------------+| admin/config | modules/system/system.admin.inc | system_admin_config_page |+--------------+---------------------------------+--------------------------+1 row in set (0.00 sec)
- How Drupal servers requests?
- How web servers work
- How web servers work?
- How Java Web Servers Work
- How Java Web Servers Work
- How Java Web Servers Work
- How Java Web Servers Work
- How Java Web Servers Work
- Chapter 1 How Drupal Works
- drupal how to install ckfinder.
- how to mount between Linux servers
- servers
- servers
- Servers
- How to use tinyfck in drupal
- How to store node content in Drupal
- How to use modules in Drupal
- 一些Drupal的How to细节处理
- Drupal line by line : part 3
- Drupal line by line : part 4
- Drupal line by line : part 5
- Use Drupal
- Guide to Drupal cache
- How Drupal servers requests?
- C规则
- Is REST the Future of SOA?
- Xoops----powerful portal and cms
- Eclipse中常用快捷键
- Joomla execution path work-through
- Joomla components and execution path
- Meta Trader
- Cookie Session