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:
[code language=”xml”]
<?xml version="1.0"?>
<config>
<modules>
<Magentotutorial_Helloworld>
<active>true</active>
<codePool>local</codePool>
</Magentotutorial_Helloworld>
</modules>
</config>
[/code]

4. Create a xml file config.xml under
app/code/local/Magentotutorial/Helloworld/etc/
With the below content:
[code language=”xml”]
<?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>
[/code]

5. Create a php file IndexController.php under
app/code/local/Magentotutorial/Helloworld/controllers/
With the below content:
[code language=”php”]
<?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();
}
}
[/code]

6. Create the layout xml file helloworld.xml under app/design/frontend/default/default/layout
[code language=”xml”]
<?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>
[/code]

7. Create the helloworld.xml template file under app/design/default/default/template/helloworld/
[code language=”html”]
<?php
echo "hello world from the template php code";
?>
<h1>Hello world message from the template html h1 tag</h1>
[/code]
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

Custom Search

Search the entire web

Custom Search