More Related Content
Similar to Magento页面载入的执行流程
Similar to Magento页面载入的执行流程 (20)
Magento页面载入的执行流程
- 2. 简介
后台对 URL 的请求是如何被翻译成到某个特定模
块的执行呢?我们来看一下下面的这个 URL :
http://example.com/frontName/actionControllerName
以反斜杠为分隔符, URL 分成以下这几部分:
- 5. 原理
URL 请求被一个 PHP 拦截,通常为前端控制器
( Front Controller )
这个 PHP 文件分析这个 URL ,获得一个执行控
制 器( Action Controller )的名字和一个执行方
法( Action Method )的名字,这个过程通常称
为路由( Routing )
实例化上一步获得的执行控制器,并调用相应的
执行方 法
- 8. 实例一
http://v2.example
.com/promoprops/index/present/?sid=v4s7fhls7i37as
v2.example.com 确定主目录文件夹
(…/chaodaxiu)
promoprops 前台控制器
(…/chaodaxiu/app/code/Promoprops)
Index 执行控制器
(…/Promoprops/IndexController.php)
present 执行方法 (public function
presentAction)
- 9. 实例一分析
public function presentAction()
{
$this->loadLayout();
$this->_setActiveMenu('promoprops');
$this->renderLayout();
}
loadLayout—— 这边的 Layout 是指:
… /chaodaxiu/app/design/layout ; 找到对应的配
置文件 promoprops.xml
- 10. 实例一分析
<promoprops_index_present>
<reference name="content">
<block type="promoprops/present" name="promoprops_present">
<block type="promoprops/subMenu"
name="promoprops_submenu" as="promoprops_submenu"></block>
<block type="core/page_pager" name="pager"/>
</block>
</reference>
</promoprops_index_present>
找到对应的块:… /chaodaxiu/app/code/Promoprops/Block/Present.php
- 11. 实例一分析
class Promoprops_Block_Present extends Core_Block_Template
{
protected function _construct()
{
$shop = Hlg::getShop();
$versionNo = $shop->getData('version_no');
if($versionNo == '3'){
$this->setTemplate('promoprops/present.phtml');
} else {
$this->setTemplate('promoprops/list_free.phtml');
}
}
}
- 12. 实例一拓展
打开 promoprops/present.phtml 文件后,发现页面内容
只包括 <div id=“wrapper” class=“promotion”>…</div>, 这
是为什么呢?
再看下配置文件 promoprops.xml ,可以看到有这么一句
: <reference name=“content”> ,说明这个页面的内容
只作为整个页面中内容而存在,完整的页面是
… /chaodaxiu/app/design/template/page.phtml
在 page.phtml 页面中,有这么一句 <?php echo $this-
>getChildHtml(‘content’) ?></div> ,于是把内容块独立
出来,可以自由的引用
- 13. 实例一拓展
默认的配置文件地址:
… /chaodaxiu/app/design/layout/core.xml
默认的配置信息:
<layout>
<default>
<block type="core/page" name="root" output="toHtml">
<block type="core/page_head" name="head" as="head" />
<block type="core/page_notices" name="global_notices" as="global_notices" />
<block type="core/page_header" name="header" as="header" />
<block type="core/page_menu" name="menu" as="menu" />
<block type="core/text_list" name="content" as="content" />
<block type="core/messages" name="messages" as="messages" />
<block type="core/page_footer" name="footer" as="footer" />
<block type="core/profiler" name="profiler" as="profiler" />
</block>
</default>
</layout>
- 14. 练习题
根据这个方法找五个不熟悉的页面
例如: http://v2.example
.com/tool/adjust/distriTotal/adjustPlanId/137785/?
sid=v4s7fhls7i37astol46gkgnir0
http://crm.example.cn/plugin/item/index/flag/dangqian/?
sid=am12vhscq9aofugc8digkknuc4