Book Image

Magento PHP Developer????s Guide, 2nd Edition

By : Allan MacGregor
Book Image

Magento PHP Developer????s Guide, 2nd Edition

By: Allan MacGregor

Overview of this book

Table of Contents (16 chapters)
Magento PHP Developer's Guide Second Edition
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Testing the route


Now that we have created our router and controller, we can test it out by opening http://magento.localhost.com/hello/index/index, for which we should see the following screen:

By default, Magento will use both the index controller and index action as defaults for each extension. So, if we go to http://magento.localhost.com/hello/index/index, we should see the same screen as the one shown in previous screenshot.

To conclude our introduction to the creation of the Magento module, let's add a new route to our controller:

  1. Navigate to the extension root directory.

  2. Open IndexController.php.

  3. Copy the following code:

    The file location is app/code/local/Mdg/Hello/controllers/IndexController.php.

    <?php 
    class Mdg_Hello_IndexController extends Mage_Core_Controller_Front_Action
    {
         public function indexAction()
      {
         echo 'Hello World this is the default action';
         }
    
         public function developerAction()
         {
             echo 'Hello Developer this is a custom controller action';
         }
    }

    Finally, let's test it out and load the new action route by going to http://magento.localhost.com/hello/index/developer.