Magento website Operation principle Analysis

Source: Internet
Author: User
Tags magento website

1. magento file directory structure diagram

2, Magento website operation principle

Magento website and the general site concept is a bit different, Magento is composed of a lot of modules, you can develop and system the same level of module replacement system module, so it is very convenient to two times development and maintenance! Magento's core Module page controls the output of all pages, and the rest of the modules update the layout of the page module page.xml to customize the page's functionality and display results.

Background configuration-Web-default pages you can set the homepage URL of the default module and home page, 404 and other pages.

If the default Web URL is set to CMS, the home page layout frame is <cms_index_index>

(1), a Magento module (taking Banner1 as an example) consists of the following files:

System load configuration file (App/etc/scutephp_banner1.xml)

Module home folder (App/code/local/scutephp/banner1)

The module configures the feature and its layout file through the Etc/config.xml configuration file in the module folder, which updates the Page.xml layout file to update the page, as well as the template file presentation effect that can be associated with it.

When the browser page opens the Magento Web site, Magento loads all the corresponding modules based on the module configuration file (appetcmodules), updates the Page.xml layout file according to the contents of the layout file, and can correlate the template file presentation effect.

Here is an explanation of some of the behavioral characteristics of the layout XML tag:

<default>

You should load the <default> nested updates for this particular page layout before loading almost any page of the store (we say ' almost all ', because some special pages like the product Picture pop-up window do not load the <default> handles in the layout).

If Magento finds a handle other than <default>, it processes the page in the specified handle (the < module name page, such as <catalog_product_view> for the product page), with a nested update to the page. For example,,<catalog_product_view> contains layout updates for product view detail pages, and <catalog_product_compare_index> contains compare product The updated layout of the page.

<block>

Magento determines the behavior and visual performance of each chunk in the page through the <block> tag. In Magento we have mentioned two types of chunks-structural blocks (structural blocks) and content blocks (contents blocks). The best way to differentiate between these two blocks is to differentiate them by the tag attributes assigned to them. The structure block usually contains the attribute ' as ', which can be called through the as value in the template (as specified by the Getchildhtml method), or it can be called with <reference> (for example) in the specified layout file through the Name property value.

Let's dig further into the existing properties of <block>.

type– This is the identifier for the module class, which defines the function of the block corresponding to the corresponding class function in the Block folder in the module Package folder. This property should not be modified.

name– This is the name, and other chunks can refer to this chunk by this name (see figure).

Before (and) after– these two methods determine the location of a content chunk within a structure block. Before= "-" and after= "-" Such a command flags the position of this chunk as the top or bottom of a structure block.

Template-The value specified by this property determines which templates are used for this chunk's functionality. For example, if the attribute value specifies ' catalog/category/view.phtml ', the program will load ' app/design/frontend/template/catalog/category/view.phtml ' Template file.

Action–<action> is used to control the functionality of the foreground, such as loading or not loading a JavaScript. The best way to learn is to understand the different action methods above for existing layout updates.

as– This property specifies that the chunk will be called in the template file. When you see the PHP method of getchildhtml (' Block_name ') in the template, you can be sure that it refers to a chunk whose value is ' block_name ' as the Reference property ' as '. (Example: Methods in the skeleton template <?= $this->getchildhtml (' header ')?> is called <block as= "header" >)

<reference>

<reference> is used to refer to another chunk. To refer to another chunk, an internal update will be applied to the <block> associated with it (see figure).

To use a reference, you can reference it by the ' name ' property value in the chunk. This property points to the ' name ' property in the label. So, if you use <reference name= "right", the block name of the response will be <block name= "" ">.

3. URL Routing and Dispatcher

Magento also uses a single-entry file mode to invoke the corresponding module according to different parameters. For example: Http://127.0.0.1/index.php/customer/account/login first receives the customer parameter and finds the App/code/core/mage/customer module based on that parameter. Then we look for the second account parameter, and we continue to look under the customer module. This parameter calls the controller/accountcontroller.php file under the Customer module by default.

Then find the third login parameter, I believe you already understand it! The Loginaction method under controller/accountcontroller.php.

Find the template based on the calling method: We continue to use the example above, if we find the customer module, the corresponding template directory in app/design/frontend/default/your theme/layout/ Customer.xml, if the file does not exist, it will be looked up to app/design/frontend/default/default/layout/customer.xml if the directory does not already exist and will be app/design/ Find in Frontend/base/default/layout/customer.xml. When the file is found, Magento will find the label according to the account parameter, and Magento will find the tag and load the corresponding chunk in the login parameter. If you don't understand it, you just need to know how to call the corresponding XML file based on the URL parameter.

The template calls the corresponding JS, CSS, Pictures: How does the template load these files?

JS and CSS files are loaded by app/design/frontend/default/your theme/layout/page.xml file. Of course, you can also write directly to the template file. Load the JS and CSS directories placed in/skin/fronted/default/your theme/next.

If the directory does not exist, it is looked up to the/skin/fronted/base/default/directory. Is the same as the inheritance mechanism of the template.

Rewrite the core module: If you want to modify the app/code/core/mage/customer/controller/accountcontroller.php file. You can copy accountcontroller.php this file and put it in app/code/local/company/customer/controller/accountcontroller.php;app/code/ Local/company/customer/etc/customer.xml;

overriding the Controller class

Require_once "mage/checkout/controllers/onepagecontroller.php";
Class Company_xcheckout_onepagecontroller extends mage_checkout_onepagecontroller{
Do something want//play it Right

}

Rewrite Block class

Require_once "mage/core/checkout/block/onepage.php";

Class Company_xcheckout_block_onepage extends mage_checkout_block_onepage_abstract{...}

Magento website Operation principle Analysis

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.