In this lesson, we are going to talk about registering your module for Magento.
When you register your module, you are letting Magento know that you have a customization that you’ve written. You let Magento know this by creating some configuration files. These files give Magento the instructions she needs in order to use your module.
First, you need to create a module registration file. This is a file that let’s Magento know your module exists.
Create a file: app/etc/modules/Coolryan_Module.xml
Inside of this module, place the following code:
1 2 3 4 5 6 7 8 9 |
<?xml version="1.0"?> <config> <modules> <Coolryan_Module> <active>true</active> <codePool>local</codePool> </Coolryan_Module> </modules> </config> |
Now, check in System -> Configuration -> Advanced -> Advanced to see if your module shows up.
Next, create the following directories: app/code/local/Coolryan/Module/etc/.
Now, create a config.xml file inside of this folder.
It should now look like this: app/code/local/Coolryan/Module/etc/config.xml.
Create some invalid markup inside this file to trigger a parse error. This ensures your file is being loaded.
1 2 3 4 |
<?xml version="1.0"?> <config> <broken___ </config> |
You should see the following error on your screen:
Now, fix the parse error by fixing the config.xml.
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <config> <modules> <Coolryan_Module> <version>1.0.0</version> </Coolryan_Module> </modules> </config> |
Congratulations! You have created and registered your first module! Sure, it doesn’t really do anything yet. These are the files and folders necessary to start building your module.
Troubleshooting
My Module Isn’t Listed in Admin
- Flush your cache (if enabled)
- Check your node nesting
- Check your file extension, (must be .xml)
My Config Does Not Break
- Is Developer Mode enabled?
- Flush Cache
- Check folder structure (casing matters!)
- Check file name (must be config.xml)
In the next lesson, we will learn how to instantiate classes.
Love it? Hate it? Want more? Leave me a comment and let me know!