Page tree
Skip to end of metadata
Go to start of metadata

Module Creator


Thanks to member Danieln for creating this PHP script to automatically create a base module given a Namespace and Module.

Credits: Danieln (creator), Alistek (contributor), Damián Culotta (contributor), Somesid (contributor), Ahsan Shahzad (contributor) 

Download Module Creator (v0.0.9.1) 

Updated: 25/08/2008 - Release Notes

#NOTE: v0.0.9.1 holds a bug that do not allow to ACL to manage module’s user level access. I am currently working on it to fix.

#ADDED: The module is now created with an upload field for example.

#ADDED: Code in the frontend controller shows how to get an object by param and by custom query .

#NOTE: Wiki post has yet to be updated with new code and explanations.

Updated: 07/04/2008 - 04:00AM CST - Release Notes

#NEW FEATURE: Now with module uninstaller and better look&feel.

#NEW FEATURE: Point to your Magento Install Directory to get you module copied to the right places right away.

#NOTE: Thanks to Barbanet the below problem should be alleviated with entering in your interface and theme at module creation time.

#NOTE: A common problem with the Module Creator has been the confusion over the use of ‘interface’ and ‘theme’.

The directories:

  1. /new/app/design/adminhtml/interface/theme/
  2. /new/app/design/frontend/interface/theme/

In a new Magento installation correspond to:


  1. /app/design/adminhtml/default/default/
  2. /app/design/frontend/default/default/

Please make sure to put your <module>.xml files in the correct ‘layout’ directories as these will determine whether your module is shown or not.

Installing the Module Creator


To install the Module Creator, you can use the Magento Connect Manager with the extension key, or install it manually as follows. Note that if you install via the Connect Manager the path it uses is /moduleCreator.

Copy the index.php file and the Blank folder to your webserver. You may want to put it in it’s own folder so that the index file does not conflict with other index files. Example:

Go to the module creator index page in your web browser, and fill in the desired module information. If you enter your Magento directory, the module creator will attempt to install the module directly into Magento, though file permissions must be set correctly for this to happen. If your file permissions are incorrect, or you do not want the module installed right away, you can leave the Magento Directory blank, and the module creator will create the module in a folder called [i]new[/i], and place it in the module creator’s folder.

Please note that if you enter in your magento directory to install to you must have the correct path. Let’s say that you have Magento installed here:

And you have the Module Creator installed here:

This means that the path that you would need to enter in the Module Creator is this:

  1. ../magento

The ‘..’ signifies one directory up.

Document Conventions


I am going to use a few common conventions here that should make it easier to figure out what you need to replace as I am making this as generic as possible.

Anything in angled brackets (including the angled brackets): < >, needs to replaced with the appropriate text..

Anything in square brackets (including the square brackets): [ ], needs to replaced with the appropriate text.

The reason I am using two different conventions here are that XML files already use angled brackets so you will only see the square brackets in use in XML files.

NOTE: All directory, file, class names are Case Sensitive unless otherwise noted.

Create Directories


Magento Modules follow a common naming scheme, Namespace_Module. This is very important to remember as you need to be careful about how you name your classes. Every custom module will be created in the directory:


The first step in creating your custom module is determining the namespace and module name. The namespace is simply an extra division that you can create you module in. This means that you can have two modules named the same thing if they are in two different namespaces. One way to use namespaces is to use your company name or initials for all of your modules. If my company name is Acme and I am creating a module called News the full module name would be Acme_News. Magento uses the namespace Mage. There is nothing stopping you from using that namespace under local, i.e. you could create Mage_News and that would work just fine.

Note : You can not use underscore within your module name

Note2: It seems that currently, if you use upper case characters in module names (expecting to show word starts since neither - nor _ is allowed)... the install will fail or rather the module will not work. Suggestion: use a single upper case character, at the beginning of the name.

Let’s setup our directory structure:


  1. Block/
  2. controllers/
  3. etc/
  4. Model/
  5.     Mysql4/
  6.         <Module>/
  7. sql/
  8.     <module>_setup/


  1. template/
  2.     <module>/

Activate Module


Magento requires there to be an XML file that tells Magento to look for and use your custom module.


 Expand source


Also you can disable your module in the Configuration menu on the backend via the Advanced tab.

NOTE: Due to a bug in Magento, whitespace is not treated correctly. This means that if you leave space in the values between node names (anything in angled brackets <> is a node), Magento will break.

As an explanation of the above code you will see that all you are changing is the [Namespace]_[Module] text and leaving everything else the same. Please note the capital P in codePool. If this is lowercase this module will not be active.

Create Controller



 Expand source

NOTE: You may notice that there is no closing, ?>, PHP tag in the code. This is a common coding style that Magento core classes use. Magento Coding Standard is similar (with some exceptions) to Zend Framework PHP Coding Standard and you can find the detailed explanations of this rule in Zend Framework Documentation

Create Configuration XML



 Expand source


NB : You can use the frontName of your choice without any link to your module name. IE : Mage_Catalog could have “mycatalog” as a frontName.

Create Helper



 Expand source

Create Models


If you are quite new to Magento you should pay attention to one of its specifics! The Constructors below are not the usualPHP-Constructors!! Keeping that in mind can save hours of frustrating crashes ;)


 Expand source



 Expand source

NOTE: The ‘<module>_id’ refers to the PRIMARY KEY in your database table.


 Expand source

SQL Setup



 Expand source

NOTE: Please note the <module> text that needs to be replaced. This SQL structure is up to you, this is merely a starting point.

Note Important: If you add fields and couldn’t save data in these fields please try to go to System→Cache Management Then 1.Flush Cache Storage 2.Flush Magento Cache.

Template Design



 Expand source

NOTE: The block type will automatically figure out what template file to use based on the second [module] declaration.

As an alternate way of declaring what template file to use you can use this:/app/design/frontend/<interface>/<theme>/layout/<module>.xml

 Expand source



 Expand source


NOTE: Uncomment anything that you would like to use and this is just a starting point and some common methods for you to try and pull the data out.


In this section I am utilizing the built-in Grid Widgets and form capabilities to create a form to allow editing and creating new items for your custom database.


Directory Additions



Here is the revised directory setup due to the additions and changes we need for the backend module.


  1. Block/
  2.     Adminhtml/
  3.         <Module>/
  4.             Edit/
  5.                 Tab/
  6. controllers/
  7.     Adminhtml/
  8. etc/
  9. Helper/
  10. Model/
  11.     Mysql4/
  12.         <Module>/
  13. sql/
  14.     <module>_setup/





These control the setup and appearance of your grids and the options that they display.

NOTE: Please note the fact that Block comes before Adminhtml in the class declaration. In any of the Magento modules in Adminhtml it is the opposite. For your module to work it has to be Block_Adminhtml otherwise you will get a ‘Cannot redeclare module...’ error.


 Expand source


 Expand source


 Expand source



 Expand source





 Expand source



 Expand source




NOTE: you need to manually add line 16, which is currently missing in this file.


 Expand source

XML Configuration Changes



 Expand source

XML Layout



 Expand source

Seperate Adminhtml Configuration


It’s also worth noting the adminhtml changes in the config.xml (above) can be placed in their own XML file instead, keeping these changes separated away:


 Expand source

Standard Magento Admin URLs, no rewrite needed


Also, rather than using a rewrite for the admin section described above, you can implement the same standard admin generated urls Magento uses. These look like: ‘/admin/[module]/index/’ instead of the above that would generate ‘/[module]/adminhtml_[module]/index/’.

To implement this different url structure you can change the following in your config.xml:


 Expand source







  • No labels