magento-banner

Magento tutorials 2: 3 Main components of Magento’s Architecture

In previous articles, we can see what is Magento and how to install Magento on Windows with XAMPP. In this article, we will introduce about Magento’s Architecture to have a comprehensive view about Magento.

Magento’s Architecture includes 3 main components:

1. Architectural overview

First of all, we need to know that Magento is a great combination of Zend Framework MVC architecture.

Inheriting from Zend: By inheriting from Zend, we can easily extend the processing of the application layer need building, easy to embed, link to the library.

Inheriting from the MVC pattern: help us to separate applications should be developed into three different components Model, View and Controller. Each component has a specific task and is independent of other components. From this we can easily build, maintain applications easily.

Magento structure {focus_keyword} Magento tutorials 2: 3 Main components of Magento’s Architecture 1

Magento tutorial 2: Magento Structure

2. Extension và module

Extension:

In short, extensions are exactly what they sound like. One or more files packaged together to extend the functionality of Magento. Strict terms and conditions prohibit extensions from modifying the core code, ensuring that any extended functionality doesn’t prohibit you from upgrading when a new version of Magento is released.

Module

A magento module has two main components is “code” and “template”.

- Code: Identify actions that modules will interact with the database.

- Template: The layout of the module based on code.

Code of template includes the following components:

- Block: A place for users to load data, adjust data from the database prior to display the data on template.

- Controller: Receive requests from users from Http, then transfer to the processing layer.

Etc: including the xml file used to config the module. Depending on each module that has different xml file.

- Helper: We will give the helper class here. The function we define in helper may be called at anywhere. Therefore, helper which holds the “tools” to help your programming process becomes easier in certain parts.

- Model: It contains the direct query to the database.

- Sql: Includes the sql statements to create tables, interact to change data…

Magento structure {focus_keyword} Magento tutorials 2: 3 Main components of Magento’s Architecture 2

Magento structure

3. Block – Layout – Template

Block

Magento block is divided into: structure block and content block

- Structure block: is blocks which is created to format the location for other blocks in a page. In magento default homepage with three column layout have structure such as: Head, Left, Content, Right, Footer

Structure Block {focus_keyword} Magento tutorials 2: 3 Main components of Magento’s Architecture 3

Structure Block

- Content Block: This is the content block, they are shown in the block structure. Each content block often display a certain content block through the template file and insert to the block’s father .. In template code of magento have default content blocks such as: Minicart, Recently viewed product, Newsletter subsription block Poll.

Content Block {focus_keyword} Magento tutorials 2: 3 Main components of Magento’s Architecture 4

Content Block

Once receiving a request from a user to display one page:

- Magento will load from the structure

- Each structure  have content blocks. Magento will gather these blocks and assigned to the corresponding block layout structure to handle the output.

- Finally, the system will return the results to the browser after the content has been formatted location.

Note:

In Magento, a Block is part of the website, we can insert them at anywhere. Besides, we also can understand it as a kind of “Small Controller», we can add anywhere on the site is developing.

Layout

Layout is the layout of the content on the magento page which is determined by the xml files, and is contained in the folder app / design / frontend / base / default / layout.

In the XML file, we will see some XML fragment is written in a parent, chidren. The xml segment is used to locate the display on the site.

To better understand the layout and relationship with the block layout and template, we will create a block and test layout the template.

A layout XML file is typically structured as follows:

01 <layout version=”0.1.0″>
02 <default>
03 <reference name=”header”>
04 <block type=”page/html_header” name=”header” as=”header”>
05 <block type=”page/template_links” name=”top.links” as=”topLinks”/>
06 <block type=”page/switch” name=”store_language” as=”store_language” template=”page/switch/languages.phtml”/>
07 <block type=”core/text_list” name=”top.menu” as=”topMenu” translate=”label”>
08 <label>Navigation Bar</label>
09 </block>
10 </block>
11 </reference>
12 </default>
13 </layout>

In the code above we have:

– <default> The handler for the URL, in this case default will load no matter what other handler is being initialized. If replace the <default> tag by <module_controller_action> tag, the blocks were put in there will load when the action is called.

– <reference> : The reference structure which calls the blocks in our theme

– <block>: A content block which defines the type of block and the template which will process the block’s outgoing data in the system. type parameter define the  module class which contain the function of the block. There are 2 ways to put a content block into a structural block. before = “-” and after = “-” are the parameters that help you to put the content block into position that you want.

In addition to this, Magento uses actions within blocks for functions which need to process the data that is input to them, for example adding CSS stylesheeds:

01 <action method=”addCss”>
02 <stylesheet>css/styles.css</stylesheet>
03 </action>
04 <action method=”addJs”>
05 <script>varien/js.js</script>
06 </action>
07 <action method=”addItem”>
08 <type>skin_css</type>
09 <name>css/styles-ie.css</name>
10 <params/>
11 <if>lt IE 8</if>
12 </action>

We’ll notice that there are several tags within the action method tag. These are processed into  an array and passed through the =  “” parameter, in this case add Css. This function the places the input into an output, ready for its appropriate template.

Template

Template is Phtml file designed and put in design folder. It includes php codes and html codes, so they have an extension is Phtml.

The effects of template is file data file and display block.

Template consists of two parts:

- Directory of magento template files, including:

+ Layout: containing the .xml file to determine the location, block on the site.

+ Template: including phtml file contains information displayed web.

- Skin folder contains css files, js, images: In the folder containing the forder css, images and also can have forder js.

- When understanding about what magento template includes we will be able to create a new template system.

For example, we need to modify the default footer on the availability of magento template, we need to copy the file footer in app / design / frontend / default / template / page / html /footer.phtml into template folder we create.

app/design/frontend/template_demo/template/page/html/footer.phtml…..

- After creating the template, we come in the admin config for website into this template to view the results can be edited as desired or not?

Posted by:

admin

1 Comment

  1. Bukola -  04/03/2015 - 1:45 AM

    Oh this is useful article for me. I’ll share this to my friends :) thanks

    Reply

Leave A Comment

Your email address will not be published. Required fields are marked (required):

Related articles


Warning: include(/home/cmsideas/public_html/lib/ip/example.php): failed to open stream: No such file or directory in /home/cmsideas/public_html/blog/wp-content/themes/blog/footer.php on line 59

Warning: include(): Failed opening '/home/cmsideas/public_html/lib/ip/example.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cmsideas/public_html/blog/wp-content/themes/blog/footer.php on line 59

Back to Top