We will see a basic hello world module in Magento. Before going for we should have some basic MVC idea in magento.
lets make a module before moving on we should have the basics as Module name usually contains 2 parts <CompanyName>_<ModuleName> or we can say it should have <Namespace>_<Module>.
Now, first will create a file Namespace_Test.xml in the location app/etc/modules/ with the code
<?xmlversion="1.0"?>
<config>
<modules>
<Namespace_Test>
<active>true</active>
<codePool>local</codePool>
</Namespace_Test>
</modules>
</config>
<Namespace_Test> Tells Name of Module.
<active> This says if the module is active or not.
<codePool> This says the location of the module i.e inside the local folder. It can also be community folder.
This file tells the magento about our module so the file is important.
Now go in the app/code/local/ and make a folder structure as create a folder namespace with the name Namespace and in that folder create another folder Test i.e., our module. Now in that Test module create folders Block, etc, Model, controllers, Helpers
Next we create the configuration file config.xml of the module at Namespace/Test/etc. with the code
<?xml version="1.0"?>
<config>
<modules>
<Namespace_Test>
<version>0.1.0</version>
</Namespace_Test>
</modules>
<frontend>
<routers>
<test>
<use>standard</use>
<args>
<module>Namespace_Test</module>
<frontName>test</frontName>
</args>
</test>
</routers>
</frontend>
<global>
<blocks>
<test>
<class>Namespace_Test_Block</class>
</test>
</blocks>
<helpers>
<test>
<class>Namespace_Test_Helper</class>
</test>
</helpers>
</global>
</config>
in the code <version>0.1.0</version> is the Version of module,
<frontName>test</frontName> This is the URL of the module.
<class>Namespace_Test_Block</class> Path of the Block Folder, where all php files are located related to view.
<class>Namespace_Test_Helper</class> Path of Helper Files
Next, we will create the Controller file. these are the files i.e., controllers files which gets executed first whenever we open the url.
Now create the controller file in the controllers folder with the code
class Namespace_Test_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo "Hello World";
}
}
we are done here to test the module write this url in your browser www.your-magento.com/test/ replace the your-magento string with your magento name string in the url. It will display the the hello world on the window.
0 Comment(s)