Since Magento is a huge framework in terms of number of files and amount of code, it is necessary to break the code into small modules so that it can be managed properly.
Magento works on modules as the basics. You will find all of the code divided into multiple modules.
The code pool
Magento provides three code pools to arrange our modules. These are:
This code pool contains various core Magento modules and as a developer, it is advised not to touch this area.
This code pool contains modules from 3rd party vendors. Again it is advised not to touch this area too.
This is the area where we are going to put our modules. If you need to override existing functionality, you are going to do it in this section only.
Directory structure of a module
Every module should follow the following directory structure as the basics. Here is the structure ( <> represents directory ):
<namespace> <modulename> <Block> <controllers> <etc> config.xml <Helper> <Model> <sql>
Namespace: Every module should be placed inside a namespace folder. This is required to remove duplicate names among modules.
Modulename: This is the actual name of your module. Now multiple modules may have same name but they can be distinguished with namespaces.
We will know more about rest of the folders in a later post. But for now, we are going to follow this directory structure.
*Note: Apart from the etc folder, none of the directories inside modulename are compulsory.
So, let us create a basic module that actually does nothing. Create the following directory structure under app/code/local folder-
<Test> <Basic> <etc>
Now create a file config.xml in the etc folder. This file defines various configuration of our module. Add the following code in this file-
<?xml version="1.0" ?> <config> <modules> <Test_Basic> <version>1.0</version> </Test_Basic> </modules> </config>
Next, we need to tell Magento about our module. For this, we will create the file test_basic.xml in app\etc\modules folder. Create the file and add following code:
<?xml version="1.0" ?> <config> <modules> <Test_Basic> <active>true</active> <!-- this module is active, false means in-active --> <codePool>local</codePool> <!-- find this module in app\code\local folder --> </Test_Basic> </modules> </config>
Your module is ready now. Now refresh the cache by logging into admin, System -> Cache Management.
Now you can check your module from System -> Configuration, on the left side, ADVANCED -> Advanced