1 / 7

Index.php

Index.php 越简洁越好 , drupal 就秉承了这原则 简约到只有三个函数 drupal_bootstrap() menu_execute_active_handler() theme(). Index.php. 一步一步,共九步,后面的一步依赖于前面的一步顺利完成,随时都有可能退出执行 每一步都干些什么 ? 查看 _drupal_bootstrap() 函数 比较难理解的几个地方 page_cache_fastpath(), 文件缓存 db_set_active() 如何进行主从数据库连接切换 SESSION 数据何时回收,加载,持久

Download Presentation

Index.php

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Index.php越简洁越好,drupal就秉承了这原则 • 简约到只有三个函数 • drupal_bootstrap() • menu_execute_active_handler() • theme() Index.php

  2. 一步一步,共九步,后面的一步依赖于前面的一步顺利完成,随时都有可能退出执行一步一步,共九步,后面的一步依赖于前面的一步顺利完成,随时都有可能退出执行 • 每一步都干些什么?查看_drupal_bootstrap()函数 • 比较难理解的几个地方 • page_cache_fastpath(), 文件缓存 • db_set_active() 如何进行主从数据库连接切换 • SESSION数据何时回收,加载,持久 • User何时对象建立!~role、user和account • Drupal缓存策略:CACHE_DISABLED,CACHE, CACHE_AGGRESSIVE • drupal_page_header() 与drupal_page_cache_header() 有啥不一样? • QueryPath Drupal化。arg()、query_path、url()、url_alias、path • 万恶的module_load_all() • 启用模块初始化module_invoke_all(‘init’) boot

  3. 一个query_path对应一个page,每个page都有一个页面函数page_callback,该函数返回值就是页面主体内容(即模板文件变量$content).一个query_path对应一个page,每个page都有一个页面函数page_callback,该函数返回值就是页面主体内容(即模板文件变量$content). • 通过函数menu_get_item()来找到与query_path相呼应的页面函数page_callback等内容。 • 函数menu_get_item()是调试的关键地方之一,这里可以知道 • 为什么输出的内容不是所预期的那样,access_callback函数 • 页面函数执行前,执行了哪些函数,加载了哪些对象,load_functions函数 • 传递给页面函数page_callback的实参是什么$router_item[‘page_arguments’] • 就像操作系统的路由表一样,drupal也维护着这样的一张表menu_router • path 这里经过一些处理的query_path,比如user/%user_load/del,则对应user/%/del • load_functions和to_arg_functions 在执行access_callbck和page_callbck前执行这些函数,负责加载相应的对象。通常load_functions负责将query_path中的参数转成逻辑对象,比如path=‘user/%user_load/del’, query_path= user/1/del 则会将1转成$user=user_load(1) • page_callback,只有当access_callback返回TRUE的时候,page_callback才会执行 • file 则是在page_callback执行之前,需要加载(require)进来的php文件 • fit 当一个query_path对应多个path的时候,取fit值最高的那个path MENU_ROUTER

  4. 右边是一个典型的menu_router记录 user/%user_uid_optional 表menu_router.path值为user/% 对应的query_path可能为user/1 arg()将query_path切为$path_map = array(‘user’, ‘1’) load_functions为user_uid_optional(它返回$user对象) 函数将user_uid_optional($map[1])转为uid=1的$user对象此时的$path_map = array(‘user’, $user) 执行access_callback来判断用户是否有权限访问请求页面,这里是user_view_access($path_map[1]), 注意这里的access_arguments 指定了$i=1,即$path_map[$i] 当user_view_access返回TRUE的时候,加载文件user.pages.inc 最后执行页面函数user_view($user),返回$content并且交给theme(‘page’, $content) 处理 MENU_ROUTER II

  5. theme($hook)主题函数 一个$hook一般有二种类型:theme和module init_theme()和_init_theme()初始化theme hook_theme 主题函数:优先执行哪个主题函数 preproccess函数:将变量推送到模板文件(*.tpl.php) theme的render函数 覆写theme函数几种方法 优先使用哪个模板文件:query_path与*.tpl.php的匹配机制 常用的theme相关函数 THEME

  6. 初使化theme,请使用函数init_theme() • theme初始化做了以下几项主要操作 • 确定用户使用哪个theme! $user->theme • 载入与主题相关的css和javascript脚本 • 确定启用哪个theme_engine,默认使用phptemplate • 执行THEME_ENGINE_init函数。实际上是载入了主题自定义函数文件path_to_theme()/template.php • 加载注册列表(_theme_load_registry).把注册到该theme相关的hook menu选项加载起来.一般从缓存中加载 THEME INIT

  7. 未完…待续…谢谢大家

More Related