Do you want to create a new page in Magento ? or Do you want to create a new module in Magento ? If yes, Then ok, just spend 10 minutes and follow below steps.
Target: Create a new module called “HelloWorld”
Step 1: Module Declaration
Create app/etc/modules/Tatva_HelloWorld.xml and write below code
1 <?xml version="1.0"?>
2 <config>
3 <modules>
4 <Tatva_HelloWorld>
5 <active>true</active>
6 <codePool>local</codePool>
7 </Tatva_HelloWorld>
8 </modules>
9 </config>
Step 2: Module Configuration
a. Create a controller class app/code/local/Tatva/HelloWorld/controllers/IndexController.php
1 class Tatva_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action
2 {
3 public function indexAction()
4 {
5 $this->loadLayout(array('default'));
6 $this->renderLayout();
7 }
8 }
b. Create a Block class app/code/local/Tatva/HelloWorld/Block/HelloWorld.php
1 class Tatva_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
2 {
3 // necessary methods
4 }
c. create configuration xml in app/code/local/Tatva/HelloWorld/etc/config.xml
01 <?xml version="1.0"?>
02 <config>
03 <global>
04 <modules>
05 <tatva_helloworld>
06 <version>0.1.0</version>
07 </tatva_helloworld>
08 </modules>
09 <blocks>
10 <helloworld>
11 <rewrite>
12 <helloworld>Tatva_HelloWorld_Block_HelloWorld</helloworld>
13 </rewrite>
14 </helloworld>
15 </blocks>
16
17 </global>
18 <frontend>
19 <routers>
20 <helloworld>
21 <use>standard</use>
22 <args>
23 <module>Tatva_HelloWorld</module>
24 <frontName>helloworld</frontName>
25 </args>
26 </helloworld>
27 </routers>
28 <layout>
29 <updates>
30 <helloworld>
31 <file>helloworld.xml</file>
32 </helloworld>
33 </updates>
34 </layout>
35 </frontend>
36 </config>
Define Frontend Template :
1. Define page layout in app/design/frontend/Tatva/default/layout/helloworld.xml
N.B: Use default instead of Tatva as template location if you use default design packages. Means create file in app/design/frontend/default/default/layout/helloworld.xml
01 <?xml version="1.0"?>
02
03 <layout version="0.1.0">
04
05 <helloworld_index_index>
06 <reference name="root">
07 <action method="setTemplate"><template>page/1column.phtml</template></action>
08 </reference>
09 <reference name="content">
10 <block type="helloworld/helloworld" name="hello" template="helloworld/helloworld.phtml"/>
11 </reference>
12 </helloworld_index_index>
13
14 </layout>
2. Create template file app/design/frontend/Tatva/default/template/helloworld/helloworld.phtml and write down
N.B: Use default instead of Tatva as template location if you use default design packages. Means create file in app/design/frontend/default/default/template/helloworld/helloworld.phtml
Hello World ! I am a Magento Guy..
Hey, new module is ready to run and hit browser with url
http://127.0.0.1/projectname/index.php/helloworld/