Magento Helloworld Module
Here are 8 steps to get started with Magento by creating your very first Magento module, helloworld.
1. Create the below directories:
app/code/local/Magentotutorial
app/code/local/Magentotutorial/Helloworld
2. Under the directory Helloworld, create the below directories:
/Block
/controllers
/etc
/Helper
/Model
/sql
3. Create a xml file Magentotutorial_Helloworld.xml under
app/etc/
With the below content:
<?xml version="1.0"?> <config> <modules> <Magentotutorial_Helloworld> <active>true</active> <codePool>local</codePool> </Magentotutorial_Helloworld> </modules> </config>
4. Create a xml file config.xml under
app/code/local/Magentotutorial/Helloworld/etc/
With the below content:
<?xml version="1.0"?> <config> <modules> <Magentotutorial_Helloworld> <version>0.1.0</version> </Magentotutorial_Helloworld> </modules> <frontend> <routers> <helloworld> <use>standard</use> <args> <module>Magentotutorial_Helloworld</module> <frontName>helloworld</frontName> </args> </helloworld> </routers> <layout> <updates> <helloworld> <file>helloworld.xml</file> </helloworld> </updates> </layout> </frontend> </config>
5. Create a php file IndexController.php under
app/code/local/Magentotutorial/Helloworld/controllers/
With the below content:
<?php class Magentotutorial_Helloworld_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction() { Mage::getSingleton('core/session')->addSuccess("Hello world message from the controller"); $this->loadLayout(); $this->_initLayoutMessages('customer/session'); $this->renderLayout(); } }
6. Create the layout xml file helloworld.xml under app/design/frontend/default/default/layout
<?xml version="1.0" encoding="UTF-8"?> <layout version="0.1.0"> <helloworld_index_index> <reference name="root"> <action method="setTemplate"> <template>page/1column.phtml</template> </action> </reference> <reference name="content"> <block type="core/template" name="helloworld" template="helloworld/helloworld.phtml"></block> </reference> </helloworld_index_index> </layout>
7. Create the helloworld.xml template file under app/design/default/default/template/helloworld/
<?php echo "hello world from the template php code"; ?> <h1>Hello world message from the template html h1 tag</h1>
6. Clear the cache by deleting all the files and directories under var/cache/
8. Assume you magento home link is http://localhost/, then you can test what you’ve done above by going to this http://localhost/helloworld/index
You should see Hello World! on the page.
Search within Codexpedia
Search the entire web