magento執行流程

轉載:http://www.imooc.com/article/4889#0-qzone-1-15797-d020d2d2a4e8d1a374a433f596ad1440

電商網站框架Magento的執行流程,一張圖就可完全說明。
這裏寫圖片描述

magento也是mvc模式的程序,但是與普通的mvc結構又有所差異。
我們通過它的一個註冊來看他的程序執行流程:
首先,我們在地址欄輸入http://localhost/magento/index.php/customer/account/create/來進入註冊的頁面。
step 1:程序拿到url中的customer會自動定位到模塊 app/code/core/Mage/Customer
step 2:然後程序得到account會自動定位到控制器文件 app/code/core/Mage/Customer/controllers/AccountController.php
step 3:程序得到create,則會在剛剛找到的控制器文件中createAction()方法。

public function createAction(){ 
    $this->_redirect('*/*'); return; 
} 
    $this->loadLayout(); 
    $this->_initLayoutMessages('customer/session'); $this->renderLayout(); 
    }

step 4:執行程序裝載目錄 app/design/frontend/base/default/layout/下的customer.xml。然後尋找名爲的標籤

<customer_account_create translate="label"> 
<label>Customer Account Registration Form</label>
 <!-- Mage_Customer --> 
 <remove name="right"/>
<reference name="root"> 
<action method="setTemplate">
<template>page/1column.phtml</template>
</action> 
</reference> 
<reference name="content"> 
<block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label"> 
<label>Form Fields Before</label> 
</block>
 </block> 
</customer_account_create>

step 5:在customer.xml中定義了要使用的block和template,相對應的文件目錄分別爲:app\code\core\Mage\Customer\Block\Form\Register.php 和app\design\frontend\base\default\template\customer\form\register.phtml
在template文件中可以使用$this來訪問類的方法。
所以,magento的程序執行流程可以歸納爲這樣:
獲得執行控制器->執行方法中處理業務邏輯和模型數據->控制器實例化佈局對象->佈局對象根據請求實例化block->block與template一一對應完成顯示邏輯

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章