directory structure:
Magento requires there to be an XML file that tells Magento to look for and use your custom module.
/app/code/local/<Namespace>/<Module>/
Block/
controllers/
etc/
Model/
Mysql4/
<Module>/
sql/
<module>_setup/
/app/design/frontend/<interface>/<theme>/
template/
<module>/
Lets assume following values
<Namespace> = Test
<Module> = Tutorial
<interface>
= green
<theme> = default
1. create module
Magento requires there to be an XML file that tells Magento to look for and use your custom module.
/app/etc/modules/<Namespace>_<Module>.xml
<?xml version="1.0"?>
<config>
<modules>
<[Namespace]_[Module]>
<active>true</active>
<codePool>local</codePool>
</[Namespace]_[Module]>
</modules>
</config>
Replaced code
<?xml version="1.0"?>
<config>
<modules>
<Test_Tutorial>
<active>true</active>
<codePool>local</codePool>
</Test_Tutorial>
</modules>
</config>
<config>
<modules>
<Test_Tutorial>
<active>true</active>
<codePool>local</codePool>
</Test_Tutorial>
</modules>
</config>
2. Create controller
/app/code/local/<Namespace>/<Module>/controllers/IndexController.php
<?php
class <Namespace>_<Module>_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
Replaced code
<?php
class Test_Tutorial_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
3. Create configuration XML
/app/code/local/<Namespace>/<Module>/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<[Namespace]_[Module]>
<version>0.1.0</version>
</[Namespace]_[Module]>
</modules>
<frontend>
<routers>
<[module]>
<use>standard</use>
<args>
<module>[Namespace]_[Module]</module>
<frontName>[module]</frontName>
</args>
</[module]>
</routers>
<layout>
<updates>
<[module]>
<file>[module].xml</file>
</[module]>
</updates>
</layout>
</frontend>
<blocks>
<[module]>
<class>[Namespace]_[Module]_Block</class>
</[module]>
</blocks>
</config>
Replaced code
<?xml version="1.0"?>
<config>
<modules>
<Test_Tutorial>
<version>0.1.0</version>
</Test_Tutorial>
</modules>
<frontend>
<routers>
<tutorial>
<use>standard</use>
<args>
<module>Test_Tutorial</module>
<frontName>tutorial</frontName>
</args>
</tutorial>
</routers>
<layout>
<updates>
<tutorial>
<file>tutorial.xml</file>
</tutorial>
</updates>
</layout>
</frontend>
<global>
<blocks>
<tutorial>
<class>Test_Tutorial_Block</class>
</tutorial>
</blocks>
</global>
</config>
4. Template design
/app/design/frontend/<interface>/<theme>/layout/<module>.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<[module]_index_index>
<reference name="content">
<block type="core/template" name="[module]" template="[module]/[module].phtml" />
</reference>
</[module]_index_index>
</layout>
Replaced code
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
<reference name="content">
</reference>
</default>
<tutorial_index_index>
<reference name="content">
<block type="tutorial/list" name="tutorial" template="tutorial/tutorial.phtml" />
</reference>
</tutorial_index_index>
</layout>
5. Creating block
/app/code/local/<Namespace>/<Module>/Block/List.php
<?php
class
<Namespace>_<Module>
_Block_List extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
//methods will goes on
}
Replaced code
<?php
class Test_Tutorial_Block_List extends Mage_Core_Block_Template
{
public function _prepareLayout()
{
return parent::_prepareLayout();
}
public function myMessage(){
return "This is test message, This is my module.";
}
}
6. create template file
/app/design/frontend/<interface>/<theme>/template/<module>/<module>.phtml
<?php $this->methidNameBlock() ;?>
Replaced code
<div>
<?php
echo 'Testing message';
echo "<BR/>";
echo $this->myMessage();
?>
</div>
7. Check your output
http://localhost/magento_1.6/tutorial/index