Magento MVC architecture & Module Development
>>>>>>>>>>>>>>>>>PHP MVC architecture<<<<<<<<<<<<<<<<<<<<<<<<
In the typical MVC pattern, the flow of the application is something like this:
1) There is main entry point - index.php - from where the entire app routing mechanism is determined.
2) Based on this routing mechanism and requested URL pattern, the app will call the appropriate controller.
3) The controller then calls the appropriate views.
4) Finally, the view files collect the data from model files and display the data.
>>>>>>>>>>>>>>>>>>Magento MVC architecture<<<<<<<<<<<<<<<<<<<<<<
Magento's MVC architecture adds a few layers to the MVC pattern, but the basic flow of control of an application is like this:
1) There is main entry point - index.php - from where the whole app will be initialized.
2) Base on the requested URL appropriate controller will be called.
3) Controller defines the pages and load the layout files for those pages.
4) Layout files tells the controllers which block files to use.
5) Block files collect the data from models and helpers files and pass it to templates files.
6) Templates files receive data and render html.
In short Form:
Based on the Requested URl appropriate controller is called
>>>>Inside Controller pages and the layout of the pages is defined
>>>Layout File calls the Block
>>Block collect the Data from the models and helpers and passed to the template file
>Templates received the data and render the data
-----------------------------------------------------------------------------------------------
Magento modules consist of the following components:
1) Blocks contain functions that are used to display data in templates.
2) Models contain the business logic of modules.
3) Resource Models contains functions that are used for database interaction.
4) Controllers defines page layout and blocks files and are loaded when a URL is requested.
5) etc contains configuration files in XML formats which tells Magento how many files modules have and how the module interacts.
6) Helpers contain functions that are used for defining common business logic (such as image resize, validation). These functions can used anywhere across the Magento application
7) sql contains SQL scripts to create, modify, or delete SQL tables.
Module Naming:
We need to give a name to our module. Generally,
Magento module names are made of two parts:
<Namespace>_<Module>.
The best practice to give a Magento module a name is choose
<Namespace>
as an author or a company name and <Module> as a actual module name.
Configure and Activate our module by creating config file
Rahul_Mymodule.xml in the app/etc/modules directory. This directory contains config files for all modules.
<?xml version="1.0"?>
<config>
<modules>
<Rahul_Mymodule>
<active>true</active>
<codePool>local</codePool>
</Rahul_Mymodule>
</modules>
</config>
Next we will create our module configuration file. This file will tell Magento all about our module.
This includes how many files our module contains, what type of files (models, helpers, database classes), and so on.
Go to app/code/local/Rahul/Mymodule/etc and create a config.xml file that will contain following content
<?xml version="1.0"?>
<config>
<modules>
<Rahul_Mymodule>
<version>0.1.0</version>
</Rahul_Mymodule>
</modules>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>Rahul_Mymodule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
</frontend>
</config>
In the <mymodule> tag, we have defined module name in <module> tag and frontend name in <frontName>.
By using a frontend name, we can access our module in frontend like yoursitename.com/index.php/mymodule/index.
By calling yoursitename.com/index.php/mymodule or yoursitename.com/index.php/mymodule/index
Magento will look for index action of your module's controller file.
As such, we need to create our controller file.
Go to app/code/local/Rahul/Mymodule/controllers and create file IndexController.php with following content.
Now let's create action: testAction .
<?php
class Rahul_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "Hello tuts+ World";
$this->loadLayout(); //loads the layout
$this->renderLayout();
}
public function testAction()
{
echo "test action";
}
}
?>
We can access the testAction using URL yoursite.com/index.php/mymodule/index/test
To find the classes in magento and its functionality
http://www.8tiny.com/source/magento/nav.html?_classes/index.html
In the typical MVC pattern, the flow of the application is something like this:
1) There is main entry point - index.php - from where the entire app routing mechanism is determined.
2) Based on this routing mechanism and requested URL pattern, the app will call the appropriate controller.
3) The controller then calls the appropriate views.
4) Finally, the view files collect the data from model files and display the data.
>>>>>>>>>>>>>>>>>>Magento MVC architecture<<<<<<<<<<<<<<<<<<<<<<
Magento's MVC architecture adds a few layers to the MVC pattern, but the basic flow of control of an application is like this:
1) There is main entry point - index.php - from where the whole app will be initialized.
2) Base on the requested URL appropriate controller will be called.
3) Controller defines the pages and load the layout files for those pages.
4) Layout files tells the controllers which block files to use.
5) Block files collect the data from models and helpers files and pass it to templates files.
6) Templates files receive data and render html.
In short Form:
Based on the Requested URl appropriate controller is called
>>>>Inside Controller pages and the layout of the pages is defined
>>>Layout File calls the Block
>>Block collect the Data from the models and helpers and passed to the template file
>Templates received the data and render the data
-----------------------------------------------------------------------------------------------
Magento modules consist of the following components:
1) Blocks contain functions that are used to display data in templates.
2) Models contain the business logic of modules.
3) Resource Models contains functions that are used for database interaction.
4) Controllers defines page layout and blocks files and are loaded when a URL is requested.
5) etc contains configuration files in XML formats which tells Magento how many files modules have and how the module interacts.
6) Helpers contain functions that are used for defining common business logic (such as image resize, validation). These functions can used anywhere across the Magento application
7) sql contains SQL scripts to create, modify, or delete SQL tables.
Module Naming:
We need to give a name to our module. Generally,
Magento module names are made of two parts:
<Namespace>_<Module>.
The best practice to give a Magento module a name is choose
<Namespace>
as an author or a company name and <Module> as a actual module name.
Configure and Activate our module by creating config file
Rahul_Mymodule.xml in the app/etc/modules directory. This directory contains config files for all modules.
<?xml version="1.0"?>
<config>
<modules>
<Rahul_Mymodule>
<active>true</active>
<codePool>local</codePool>
</Rahul_Mymodule>
</modules>
</config>
Next we will create our module configuration file. This file will tell Magento all about our module.
This includes how many files our module contains, what type of files (models, helpers, database classes), and so on.
Go to app/code/local/Rahul/Mymodule/etc and create a config.xml file that will contain following content
<?xml version="1.0"?>
<config>
<modules>
<Rahul_Mymodule>
<version>0.1.0</version>
</Rahul_Mymodule>
</modules>
<frontend>
<routers>
<mymodule>
<use>standard</use>
<args>
<module>Rahul_Mymodule</module>
<frontName>mymodule</frontName>
</args>
</mymodule>
</routers>
</frontend>
</config>
In the <mymodule> tag, we have defined module name in <module> tag and frontend name in <frontName>.
By using a frontend name, we can access our module in frontend like yoursitename.com/index.php/mymodule/index.
By calling yoursitename.com/index.php/mymodule or yoursitename.com/index.php/mymodule/index
Magento will look for index action of your module's controller file.
As such, we need to create our controller file.
Go to app/code/local/Rahul/Mymodule/controllers and create file IndexController.php with following content.
Now let's create action: testAction .
<?php
class Rahul_Mymodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "Hello tuts+ World";
$this->loadLayout(); //loads the layout
$this->renderLayout();
}
public function testAction()
{
echo "test action";
}
}
?>
We can access the testAction using URL yoursite.com/index.php/mymodule/index/test
To find the classes in magento and its functionality
http://www.8tiny.com/source/magento/nav.html?_classes/index.html
Comments
Post a Comment