As we know now magento directory structure (refer for directory structure). Now, let’s create one basic Hello World custom module. In that we just display one static message. So for that create below mentioned directory structure in side your root directory.
app/etc/modules/Webmull_Helloworld.xml
app/code/local/Webmull/Helloworld/etc/config.xml
app/code/local/Webmull/Helloworld/Block/Helloworld.php
app/code/local/Webmull/Helloworld/controllers/IndexController.php
app/design/frontend/rwd/webmull/layout/helloworld.xml
app/design/frontend/rwd/webmull/template/helloworld/helloworld.phtml
Create global configuration file inside etc directory:
As for custom module, we have to tell to magento system for it global configuration like it’s active or not and/or which ‘Code Pool’ we have to use for our module. This can we done with global ‘etc/module’ directory. We have to create one file under the app/etc/modules/Modulename.xml. Please remember name of first character of ‘namespace’ and ‘modulename’ must be Capital. In our case we can set our global configuration under below file:
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <Webmull_Helloworld> <active>true</active> <codePool>local</codePool> </Webmull_Helloworld> </modules> </config> |
Create module configuration file inside app/code/coodPool/Namespace/Modulename/etc/config.xml:
In module configuration file we mention module version, block path, resources path, routers information & layout information. Please add below code into below mentioned file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<config> <modules> <Webmull_Helloworld> <version>1.0.0</version> </Webmull_Helloworld> </modules> <global> <blocks> <helloworld> <class>Webmull_Helloworld_Block</class> </helloworld> </blocks> </global> <frontend> <routers> <helloworld> <use>standard</use> <args> <module>Webmull_Helloworld</module> <frontName>helloworld</frontName> </args> </helloworld> </routers> <layout> <updates> <helloworld module="Webmull_Helloworld"> <file>helloworld.xml</file> </helloworld> </updates> </layout> </frontend> </config> |
Create block file :
1 2 3 4 |
class Webmull_Helloworld_Block_Helloworld extends Mage_Core_Block_Template { } |
Create controller file:
1 2 3 4 5 6 |
class Webmull_Helloworld_IndexController extends Mage_Core_Controller_Front_Action{ public function indexAction(){ $this->loadLayout(); $this->renderLayout(); } } |
Create layout configuration file:
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="content"> <block type="helloworld/helloworld" name="helloworldcontent" template="helloworld/helloworld.phtml"/> </reference> </helloworld_index_index> </layout> |
Create template file:
1 |
hello world. |