Magento module
Modules are the core functioning unit in a Magento system. Here I am giving an overview of how to write a “Hello World” module in magento. Simple basics before start you cooking :-)At the time of instantiating, magento system reads all the Xmls inside the folder /app/etc/modules/ to get the list of active modules and their corresponding code repository . So very first step of creating a magento module is to declare the module and its core repository(the repository of the module, in magento it’s calles codepool ).
If you open /app/code/ you will see 3 coodpool :- core, community and local.
app/
|–code/
| |—community/
| |—core/
| |—local/
|
Download Magento Module
The “core” cood pool is dedicated for magento’s all system modules. The “community” codepool is for all modules developed by magento’s partners and local is the codepool dedicated for you as a developer to write your own customized code.
In Magentos’ all modules are organized under a package. This package is nothing but a simple folder under codepool containing different modules. For example all core modules of magento system is kept unde package “Mage” (open the folder /app/code/code/ , you see the folder “Mage” under which all system module resides).
Namespace: Company
Modulename : Web
Step 1: Declare your shell module and it’s code pool
Create an xml file /app/etc/modules/Company_Web.xml (You can use any name, even you can use a single file to declare number of modules).
<?xml version="1.0"?>
<config>
<modules>
<Company_Web>
<active>true</active>
<codePool>local</codePool>
</Company_Web>
</modules>
</config>
Step 2:
Create the basic directory structure under /app/code/local/ :-
Company/
|–Web/
| |–Block/
| |–controllers/
| |–etc/
| |–Helper/
| |–sql/
|
Step 3:
Write the front controller in app\code\local\Company\Web\controllers\IndexController.php
<?php
class Company_Web_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}Step 4: Finally create the template file of your module app\design\frontend\default\default\template\web\web.phtml
<?php echo "Welcome to your custom module...."; ?>
Step 5: Add the layout.xml as app\design\frontend\default\default\layout\web.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<default>
</default>
<web_index_index>
<reference name="content">
<block type="web/web" name="web" template="web/web.phtml" />
</reference>
</web_index_index>
</layout>
Step 6: Now write the helper class app\code\local\Company\Web\Helper\Data.php
<?php
class Company_Web_Helper_Data extends Mage_Core_Helper_Abstract
{
}
Step 7:
Create the config file as app\code\local\Company\Web\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Web>
<version>0.1.0</version>
</Company_Web>
</modules>
<frontend>
<routers>
<web>
<use>standard</use>
<args>
<module>Company_Web</module>
<frontName>web</frontName>
</args>
</web>
</routers>
<layout>
<updates>
<web>
<file>web.xml</file>
</web>
</updates>
</layout>
</frontend>
<global>
<models>
<web>
<class>Company_Web_Model</class>
<resourceModel>web_mysql4</resourceModel>
</web>
<web_mysql4>
<class>Company_Web_Model_Mysql4</class>
<entities>
<web>
<table>web</table>
</web>
</entities>
</web_mysql4>
</models>
<resources>
<web_setup>
<setup>
<module>Company_Web</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</web_setup>
<web_write>
<connection>
<use>core_write</use>
</connection>
</web_write>
<web_read>
<connection>
<use>core_read</use>
</connection>
</web_read>
</resources>
<blocks>
<web>
<class>Company_Web_Block</class>
</web>
</blocks>
<helpers>
<web>
<class>Company_Web_Helper</class>
</web>
</helpers>
</global>
</config>


Magento is a leading eCommerce platform. I think this tutorial will really help the beginners to start with Magento module.
ReplyDeleteVery good post! Greet thank you.
ReplyDeleteAnd you showed how this example can be verified - that is more important as for me.
Thanx...
ReplyDeleteHoly Crap!
ReplyDeleteThat is the most work for a 'hello world' that i have ever seen
Magento is a very good CMS which is providing a more features and facility.So,this blog is giving a good information on the Magento....thanks...
ReplyDelete-magento mobile
Hello,
ReplyDeleteI followed your code for creating a new module and also create according to your instruction and structure but still i am getting 404 not found error. I am fresher in magent. Can u help me !
Thanks,
kamal
I followed all above steps and successfully got one more tab on admin panel menu but when clicking the Add New only a blank page is displayed. What to do?
ReplyDeletePlease Help as early as possible...
Thanx in Advance
Hi, I will, upload the zip file of the module by this evening. Please be patient.
ReplyDeleteTere is a typo in step 2:
ReplyDeleteStep 2:
Create the basic directory structure under /app/code/core/local/ :-
the correct path should be "/app/code/local/"
Thanks for the notice Senor. The typo has been corrected.
ReplyDeletehi arvind. i cnt see any of the input types in the admin panel tab.
ReplyDeleteim using 1.5 ver of magento. please try to help it out thanks
help me Magento please!
ReplyDeleteI am not start from start?
ReplyDeleteplz give short description also ,it's helpful for understanding the code.
ReplyDeleteTHANX
what is the link of example, i try this
ReplyDeletehttp://127.0.0.1/dev/index.php/Company i get 404 error
Thanks a lot man.At first it didn’t workout but after clearing the cache it works fine. Great post. keep it up…..
ReplyDeleteThanks. Good tutorial!
ReplyDeleteHow can I show this module in Magento?
ReplyDeleteI am curious how it can be done in the template and as block in a CMS page.
Good day!
ReplyDeletetook your zip-file, unzipped it in / app
but the module is not installed correctly
have a position in System -> Advenced -> Disable Modules Output (Enable)
admin menu in no position Company
how can there be problems?
Thank you!
P.S. magemto 1.6.0
what url do i use to view the hello world module?
ReplyDeletehow to call module in url?
ReplyDeleteplease give me path of url
how to call module in url
ReplyDeletepleas e give me path of url
Hi Nikul,
ReplyDeleteYou can call it as : http://127.0.0.1/projectname/index.php/web/
if you don't khnow what to do after this tutorial you can check here to have more advanced tutorial:
ReplyDeletehttp://www.about-magento.com/magento-developper-guide-howto-tutorial-5
i hope it'll help
Pierre FAY
hi arvind ! you have posted very good tutorial and is beneficial specially for the beginners.
ReplyDeletethanks
Thanks:)
ReplyDeletehi arvind,
ReplyDeleteI have called module at front by this url http://127.0.0.1/projectname/index.php/web/
but can I control content of this module from admin.
Hi Amit,
ReplyDeleteThis module shows the frontend functionality only. To know about backend functionality read this tutorial.
This blog Is very informative, I found it helpful..
ReplyDeleteI just follewed the steps but It still getting blank page. it means that my phtml page in \default\default\layout\web.xml is not called. Anyone can help me pls.. Thanks
ReplyDelete"I just follewed the steps but It still getting blank page. it means that my phtml page in \default\default\layout\web.xml is not called. Anyone can help me pls.. Thanks"
ReplyDeleteI am getting the same problem. Can anyone help?
Really great post. This post will help to all Magento Developers.
ReplyDeleteThanks for sharing.
Very great tutorial about Magento Module but i think it is incomplete. As This module shows the frontend functionality only. And what about backend functionality?
ReplyDeleteGreat Article,thanks!
ReplyDeleteVery useful post. I really appreciate your blog.
ReplyDeleteThanks
I just follewed the steps but It still getting blank page. it means that my phtml page in \default\default\layout\web.xml is not called. Anyone can help me pls.. Thanks"
ReplyDeleteI am getting the same problem. Can anyone help?
add one more step..
app\code\local\Company\Web\block\web.php
setTemplate('web/web.phtml');
}
}
?>
setTemplate('web/web.phtml');
ReplyDelete}
}
?>
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteFinally got this to work from your source files. Can you please explain what each step does.
ReplyDeleteStep 3:
Write the front controller in app\code\local\Company\Web\controllers\IndexController.php
Something like this... what does the indexcontroller do? Thank you this tutorial helped me understand magento a little bit. Do you have any tutorials to create simple back end things like text areas or inputs?
I have follow all the steps and recheck many times but module is not working...any one can help me ?
ReplyDeleteIt is not showing in the backend. Please help me to show, can any one help me?
ReplyDeleteHow to control this "Company_Web" functionality?
ReplyDeleteFunctionality in backed and how to view in front end?
ReplyDeleteYou can call it as : http://127.0.0.1/projectname/index.php/web/
Deletebut not working......:(
DeleteThis is really interesting and very nicely documented articles. I hope this will certainly helps all the Magento naive to start with this.
ReplyDeleteThanks for sharing.
Hello This is really good tutorial and helped me a lot but I want to display the data from my backend to my frontend. In Web.phtml i have called the function as $web = $this->getWeb();
ReplyDeleteprint_r ($web);
But not able to see the data in the frontend Web page. If u can help me with this it will be great.
Thanks
Please use models and blocks to get data on frontend.
Deletei have installed magento 1.7.0 and i want to create new module in magento , i follow all steps as mention above but i can't see how module is working can anyone help me?
ReplyDeleteI think you should clear the cache.
Deletei have clear cache but still i can't get output is there any other way?
ReplyDeleteif u help me then it will be great .
Did you download the fresh module and then tried?
Deleteare there any small size extensions available for initial learning purpose? if yes then please send me links it will be very helpful for me ,
ReplyDeletethanks in advance.
Hi Arvind, Please reply my post Its urgent.
ReplyDeleteThanks
Mahak
Great, thank for this tip.
ReplyDeleteMagento is too difficult.
I also find out an other basic tip at http://xme.im/develop-hello-world-magento-extension and http://inchoo.net/ecommerce/magento/programming-magento/magento-hello-world-module-extension/ I think that usefull for newbie. Thank to all.
Great thanks for giving such good links for magneto starter .
ReplyDeleteThanks you all,
Hey,
ReplyDeleteVery informative artical Thanks For Sharing ,This artical is very useful for those who are new in magento platform ,
thanks for sharing and keep updating..
Thank you so much... I was looking for this module and it worked perfectly fine..
ReplyDeleteKeep it up !!!!
Thanks a lot for this intro tutorial. Now I really understand how Magento works with Modules.
ReplyDeleteThis worked at first, then it STOPPED working.
ReplyDeleteWhat is the url again?
Can someone help me set up routing with multi store setup?
ReplyDeletethanks guys its very helpful create module's for new magento friends,
ReplyDeletethanks once again....friends
very helpful post for magento freshers thnks you very much
ReplyDeleteworks great....
ReplyDeletemore help on code would have been great
tnx :)
thanks a lot... it is a great.... but please anyone tell me how to show back end items in the front end. thanks.
ReplyDeletethanks... this is a great tutorial... but please tell me how to display added items in the frontend.
ReplyDeletetnx:)
You can call it as : http://127.0.0.1/magento/index.php/web/
Deletethanks.....great tutorial..
ReplyDelete