Magento’s execution process can be fully explained in one picture.
Magento is also an MVC model program, but it is different from the ordinary MVC structure.
Let’s look at its program execution process through one of its registrations:
First, we enter http://localhost/magento/index.php/customer/account/create/ in the address bar to enter the registration page.
step 1: When the program gets the customer in the url, it will automatically locate the module app/code/core/Mage/Customer.
step 2: Then when the program gets the account, it will automatically locate the controller file app/code/core/Mage/Customer/ controllers/AccountController.php
step 3: When the program gets create, it will createAction() method in the controller file just found.
<code>public function createAction(){ if ($this->_getSession()->isLoggedIn()) { $this->_redirect('*/*'); return; } $this->loadLayout(); $this->_initLayoutMessages('customer/session'); $this->renderLayout(); }</code>
step 4: Execute customer.xml under the program loading directory app/design/frontend/base/default/layout/. Then look for the tag named
<code><customer_account_create translate="label"> <label>Customer Account Registration Form</label> <!-- Mage_Customer --> <remove name="right"/> <remove name="left"/> <reference name="root"> <action method="setTemplate"><template>page/1column.phtml</template></action> </reference> <reference name="content"> <block type="customer/form_register" name="customer_form_register" template="customer/form/register.phtml"> <block type="page/html_wrapper" name="customer.form.register.fields.before" as="form_fields_before" translate="label"> <label>Form Fields Before</label> </block> </block> </reference> </customer_account_create></code>
step 5: The block and template to be used are defined in customer. You can use $this to access class methods.
So, Magento’s program execution process can be summarized as follows:
Get the execution controller->Process business logic and model data in the execution method->The controller instantiates the layout object->The layout object instantiates the block according to the request- >Block and template correspond one-to-one to complete the display logic.