Create an magento extension with custom database table

Create an magento extension with custom database table

For,a newcomer magento developer,it is not easy to create an magento extension with custom database.
There are few steps to create an extension.
First of all create module control file Module name as Amit_Custommodule.xml at app/etc/modules/.

Which is enabling and disabling that custom module.First of all define CodePool of extension.

There are two type of codePool one local another community.
Suppose i am using community.Then the code of Amit_Custommodule.xml are:

Create a config.xml ,where we are declared table,model,blocks,layouts file , controllers,In a word we can say configuration file that extension.

Path Of config.xml is app/code/community/Amit/Custommodule/etc/

As we define codepool is community then it path app/code/community

Here Amit folder is Namespace of module and Custommodule is module name


Here code of config.xml

First define the table sql file install-1.0.0.php path app/code/community/Amit/Custommodule/sql/custommodule_setup/



Now ,we define the model of the module.which fetch ,delete,update data from table

Model file Custommodule.php path is app/code/community/Amit/Custommodule/Model


If we define model then we need define resource class of model Custommodule.php

Resource class my module is Custommodule.php app/code/community/Amit/Custommodule/Model/Resource/

code is

this two files makes final module Mage::getModel(“custommodule/custommodule”)->load($primaryKeyOfTable);

Now we need to class collection file of that module which is fetch all data of the table

Collection file path is Collection.php app/code/community/Amit/Custommodule/Model/Resource/Custommodule


This class provide code Mage::getModel(“custommodule/custommodule”)->getCollection();

Date:Apr 15, 2014


Now ,i am start to call frontend routers and for that reasoon i have add routers in config.xml and add the below code after


Here above code custommodule is routers ,If you want to any url from this modules then url like yousiteurl/custommodule

create an controller,which is generally called as routers

IndexController.php path is app/code/community/Amit/Custommodule/controllers/

As magento follow this stucture, yoursiteurl/index.php/fontname/controllers/action

then url is yoursiteurl/index.php/custommodule/index/index

I am declaring block class in config.xml and need to add block with in global tag



Next step , i define phtml files in layout xml file… and here layout file for that module is custommodule.xml and it also need to declare in config.xml

code of custommodule.xml path app/design/frontend/yourpackage/your template/layout/

And phtmls are located in app/design/frontend/yourpackage/your template/template/custommodule

code of custommodule.phtml is

As define block type of phtml is “custommodule/custommodule” and the block class is Amit_Custommodule_Block_Custommodule and Custommodule.php located in app\code\community\Amit\Custommodule\Block














Leave a Reply

Your email address will not be published. Required fields are marked *