CREATE YOUR MAGENTO MODULE
1.1 Defining your module
Once you've set up magento and entered into the root magento directory, go into app/code/local/. This will be where your module lives on the system. The first folder is your namespace, usually your company name. Then directory underneath this is your module name.
All your module folder will live underneath this module directory. We will create many here, but for starters just create the etc/ and controllers/ directories. We will also create a file called config.xml in this etc/ directory. This is the main, and incredibly important, configuration file for your module.
Create this folder structure now. Your directory layout should look as follows:
The content of config.xml should be as follows. It adds this module to the rest of the <modules> in the magento system. And everything is in a module, even the 'core' magento classes live within modules.
This config.xml specifies the full module name and a version number. The module name, NAMESPACE_MODULE, is derived from the aforementioned folder name. This is very common pattern in magento. Take note.
But our module doesn't actually do anything currently. We need to add a 'route' going from a URL to a class we define. This will in turn actually do something. Alter your config.xml like so to add that route.
This modification we're adding to the <frontend> of the system (i.e. not the admin panel). And we're adding a router to the other <routers> in the system. We're giving that router a name, useful when dealing with layouts later on.
Then we say it <use>s the ‘standard’ frontend router system. Then it defines the important arguments (<args>): It’ll go to the <module> we’ve just defined. And its all important url, called the <frontName>.
We’ll now define the PHP class that will be called via that route. Meaning, it will be called when the user goes to <magentourl>/URLNAME.
This will call a class in your controllers/ module directory. The default class that it will call is IndexController.php. And within that class the default method it will call will be indexAction(). All controller class methods called from the outside must have 'Action' suffixed to their name.
If you don’t use these defaults, you have to specify the controller name and action name after URLNAME i.e. [magentourl]/URLNAME/controllername/actionname, as opposed to just [magentourl]/URLNAME. [magentourl]/URLNAME/index/index is the same as just loading [magentourl]/URLNAME
Let’s create that controllers/IndexController.php class now. Its name must be prepended by the Namespace and Module name. All controllers must must have the word Controller at the end. (But you don’t need to use the word 'Controller' should you need to specify the controller in the url.)
The will extend Mage_Core_Controller_Front_Action to allow it to work as a controller and to give it access to various methods and properties of the system.
public function indexAction()
So if you go to <magentourl>/URLNAME you should see your new page. It will do nothing except display the words 'hihi'. Not impressive--but a start.
You may also want to define a route to the admin panel. But that topic will be dealt with after part I. This is because you will be applying much of what you have learnt dealing with magento's frontend.