-
Book Overview & Buying
-
Table Of Contents
Getting Started with Magento Extension Development
By :
By itself, the content of the app/code/community/Foggyline/HappyHour/etc/config.xml file won't have any additional effect on Magento, so let's move on to extending our extension. First, we will create a controller in order to output Hello World to the browser. To do this, we need to add the routers definition in frontend to our config.xml file.
<?xml version="1.0"?>"?>
<config>
<!-- … other elements ... -->
<frontend>
<routers>
<foggyline_happyhour>
<use>standard</use>
<args>
<module>Foggyline_HappyHour</module>
<frontName>happyhour</frontName>
</args>
</foggyline_happyhour>
</routers>
</frontend>
<!-- … other elements ... -->
</config>The frontend tag refers to a Magento area. Magento has three distinctive areas: frontend, admin, and install. The frontend area is what your customers see, the public facing shopping cart. The admin area is what your Magento admin users see, the administrative interface. The install area is what you see the very first time you install Magento, the installation process.
The routers tag encloses the configuration information about routers.
The frontName tag is sort of an alias for the desired route we want Magento to react to.
When a router parses a URL, it gets separated as follows: http://example.com/frontName/actionControllerName/actionMethod/. By defining a value of happyhour in the <frontName> tag, we're telling Magento that we want the system to respond to URLs in the form of http://example.com/happyhour/*.
It's important to understand that frontName and the Front Controller object are not the same thing.
The foggyline_happyhour tag should be the lowercase version of your extension name. Our extension name is Foggyline_HappyHour; this tag is foggyline_happyhour.
The extension tag should be the full name of your extension, including its namespace/extensionname name. This will be used by the system to locate your controller files.
Now we need to create a controller file. The module controller files are stored under the controllers subfolder. So let's create an app/code/community/Foggyline/HappyHour/controllers/HelloController.php class file with the following content:
<?php
class Foggyline_HappyHour_HelloController extends Mage_Core_Controller_Front_Action
{
public function helloWorldAction()
{
echo 'Hello World #1.';
}
}Once you are done, you can try opening the following URL in the browser: http://magento.loc/index.php/happyhour/hello/helloWorld. You should be able to see the Hello World #1. message. The URL path is constructed from your config.xml router frontName, the controller name itself, and the controller action name. There are two main types of controllers in Magento:
frontend: This contains all the controller classes that extend (derive from) the Mage_Core_Controller_Front_Action class
backend / admin: This contains all the controller classes that extend (derive from) the Mage_Adminhtml_Controller_Action class
URLs for admin controller actions can only be accessed if you are logged in to the Magento administration interface.
Change the font size
Change margin width
Change background colour