Magento : How To Create A First Hello Module

You can create a simple custom module in Magento to add your custom functionality to your Magento website.

Please find the steps below to create a simple hello module:

1) First Create an XML file using “Namespace_Module.xml” in the “app/etc/modules/” directory which registers your module in Magento.

Ex. Lekhraj_Myfirstmodule.xml containing the following code snippet:

<?xml version=”1.0″?>
<config>
<modules>
<Lekhraj_Myfirstmodule>
<active>true</active>
<codePool>local</codePool>
</Lekhraj_Myfirstmodule>
</modules>
</config>

2) Next you need to create a module configuration file as config.xml which tells that what a module does.

File location: app/code/local/Lekhraj/Myfirstmodule/etc/config.xml

Ex.

<?xml version=”1.0″?>
<config>
<modules>
<Mynamespace_Mymodule>
<version>1.0.0</version>
</Mynamespace_Mymodule>
</modules>
<frontend>
<routers>
<myfirstmodule>
<use>standard</use>
<args>
<module>Lekhraj_Myfirstmodule</module>
<frontName>myfirstmodule</frontName>
</args>
</myfirstmodule>
</routers>
</frontend>
</config>

3) Create a controller to access our module in frontend with url as “yoursitename.com/index.php/myfirstmodule/index/index”

File location: app/code/local/Lekhraj/Myfirstmodule/controllers/IndexController.php

In the above url, after index.php, there is moduleName/controllerName/actionName which calls your module.

Ex.
<?php
class Lekhraj_Myfirstmodule_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo “Hello test World”;
}
}

Finally, just hit the url as “yoursitename.com/index.php/myfirstmodule/index/index” and see the text “Hello test World”. That’s it your module is ready.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s