Develop “Hello world” Magento extension
To develop magento extension, first of all, we must understand about Magento Folder Structure. It you are doing some update but no changing, try to disable Magento cache at System/Cache Management.
All magento extension should be place in /app/code/community. In /app/code you also see core folder, sometime may be local folder which is created by other extension. The community or local called Code Pool.
Begining, we create our extension folder structure, if my company named Bb, and my extension name is Product, I will create the folder structure /app/code/community/Bb/Product. It’s mean our extension stay in community Code Pool and our extension is Bb_Product.
Store your extension information in /app/code/community/Bb/Product/etc/config.xml. The simple extension config file may be follow:
-
<config>
-
<modules>
-
<bb_product>
-
<version>1.0>
-
>
-
>
-
>
Now, our extension has it own profile, to let Magento load and control your extension, you must tell it “Heyx, load my extension please, my extension is Bb_Product in community Code Pool!”, so just create /app/code/etc/modules/Bb_Product.xml file:
-
<config>
-
<modules>
-
<Bb_Product>
-
<active>true>
-
<codePool>community>
-
>
-
>
-
>
That enough, our extension now can be loaded by Magento and you can enable or disable our extension in Admin Control Panel at System/Configuration/Advanced.
The next mission is create a page that output “Hello world”. Magento is base on Zend, so Magento is MVC base. If you don’t know anything about MVC, you should try to understand it first!
Create IndexControler.php file in /app/code/community/Bb/Product/controllers (offcourse, create /app/code/community/Bb/Product/controllers first)
Tell Magento know when should it use our controller, append some code into /app/code/community/Bb/Product/etc/config.xml.
-
<config>
-
<modules>
-
<Bb_Product>
-
<version>1.0>
-
>
-
>
-
<frontend>
-
<routers>
-
<bbproduct>
-
<use>standard>
-
<args>
-
<module>Bb_Product>
-
<frontName>bbproduct>
-
>
-
>
-
>
-
>
-
>
You have already created Hello world magento extension. Visit our extension at:
- http://yourdomain.com/index.php/bbproduct/index/index (it is the same with http://yourdomain.com/index.php/bbproduct/index or http://yourdomain.com/index.php/bbproduct).
You should see “Hello world” text. - http://yourdomain.com/index.php/bbproduct/index/myaction.
This output “Hello world, this is myaction” - http://yourdomain.com/index.php/bbproduct/index/myaction2
This action will output default Magento page template.
By
You are reading a post from a man who have passionate interest in information technology :). Details about me are here https://linkedin.com/in/truonghua/ and I'm willing to connect with passionate and motivated people.