官术网_书友最值得收藏!

Controllers

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.

主站蜘蛛池模板: 惠来县| 上栗县| 平邑县| 松溪县| 通城县| 沁阳市| 剑川县| 衡水市| 颍上县| 商洛市| 丹棱县| 施甸县| 壶关县| 靖远县| 手游| 平遥县| 印江| 杂多县| 香港| 巧家县| 塔河县| 竹北市| 荔波县| 桦南县| 南和县| 和田县| 凤台县| 太仆寺旗| 赣榆县| 金秀| 博白县| 睢宁县| 隆回县| 新疆| 和平县| 烟台市| 榕江县| 潼关县| 原平市| 周口市| 泽普县|