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(){ if ($this->_getsession()->isloggedin()) { $this->_redirect('*/*'); return; } $this->loadlayout(); $this->_initlayoutmessages('customer/session'); $this->renderlayout();}
step 4:执行程序装载目录 app/design/frontend/base/default/layout/下的customer.xml。然后寻找名为的标签
customer account registration formpage/1column.phtmlform fields before
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一一对应完成显示逻辑。
以上就介绍了magento的执行流程?,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。