您的位置:首页 > 其它

magento执行流程

2017-03-07 14:57 134 查看
转载: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一一对应完成显示逻辑
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: