Categories


Archives


Recent Posts


Categories


Logging Magento’s Controller Dispatch

astorm

Frustrated by Magento? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

No Frills Magento Layout is the only Magento front end book you'll ever need. Get your copy today!

This entry is part 6 of 43 in the series Miscellaneous Magento Articles. Earlier posts include Magento Front Controller, Reinstalling Magento Modules, Clearing the Magento Cache, Magento's Class Instantiation Abstraction and Autoload, and Magento Development Environment. Later posts include Magento Configuration Lint, Slides from Magento Developer's Paradise, Generated Magento Model Code, Magento Knowledge Base, Magento Connect Role Directories, Magento Base Directories, PHP Error Handling and Magento Developer Mode, Magento Compiler Mode, Magento: Standard OOP Still Applies, Magento: Debugging with Varien Object, Generating Google Sitemaps in Magento, IE9 fix for Magento, Magento's Many 404 Pages, Magento Quickies, Commerce Bug in Magento CE 1.6, Welcome to Magento: Pre-Innovate, Magento's Global Variable Design Patterns, Magento 2: Factory Pattern and Class Rewrites, Magento Block Lifecycle Methods, Goodnight and Goodluck, Magento Attribute Migration Generator, Fixing Magento Flat Collections with Chaos, Pulse Storm Launcher in Magento Connect, StackExchange and the Year of the Site Builder, Scaling Magento at Copious, Incremental Migration Scripts in Magento, A Better Magento 404 Page, Anatomy of the Magento PHP 5.4 Patch, Validating a Magento Connect Extension, Magento Cross Area Sessions, Review of Grokking Magento, Imagine 2014: Magento 1.9 Infinite Theme Fallback, Magento Ultimate Module Creator Review, Magento Imagine 2014: Parent/Child Themes, Early Magento Session Instantiation is Harmful, Using Squid for Local Hostnames on iPads, and Magento, Varnish, and Turpentine.

I’m taking a quick break from the Magento series as I plumb the depth of EAV and get through a crunch phase at The Day Job™. In the selfless interest of helping out the internet and the selfish interest of keeping my front page free of moldy content, I thought I’d pass on a simple Controller dispatch logging patch for Magento. This is mainly useful when you’re setting up a new Module and can’t figure out why Magento won’t see it, or if Magento keeps throwing the CMS 404 page in your face

A Few Caveats

  1. These files are not a true Magento Module. While powerful, creating something like this with Magento’s override system would be an order of magnitude harder

  2. Because of the above, I can’t make any promises about using this with a anything but Magento version 1.3.2.3

  3. Standard caveats about production servers apply. Use at your own risk, no warranties, etc.

Installing

Take the “Mage” folder (1.3.2.3/Mage) and place it in

app/code/local

so that your directory tree looks like

local/Mage/Core/Controller/Varien/Action.php
local/Mage/Core/Controller/Varien/Front.php
local/Mage/Core/Controller/Varien/Router/Standard.php
local/Mage/Core/Model/App.php

Then, enable logging and you should start seeing messages in your system.log that look something like

2009-09-20T16:55:48+00:00 DEBUG (7): Matching router [standard] = Mage_Core_Controller_Varien_Router_Standard  vs. request
2009-09-20T16:55:48+00:00 DEBUG (7): Module: helloworld
2009-09-20T16:55:48+00:00 DEBUG (7): Found Modules: Array
(
    [0] => Alanstormdotcom_Helloworld
)

2009-09-20T16:55:48+00:00 DEBUG (7): Setting Route Name [helloworld] on request
2009-09-20T16:55:48+00:00 DEBUG (7): Passing request into controller Alanstormdotcom_Helloworld_IndexController
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Module Name to: helloworld at Mage_Core_Controller_Varien_Router_Standard::match(248)
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Controller Name to: index at Mage_Core_Controller_Varien_Router_Standard::match(250)
2009-09-20T16:55:48+00:00 DEBUG (7): Setting Action Name to: index at Mage_Core_Controller_Varien_Router_Standard::match(252)
2009-09-20T16:55:48+00:00 DEBUG (7): Calling dispatch method on Alanstormdotcom_Helloworld_IndexController
2009-09-20T16:55:48+00:00 DEBUG (7): Action Controller: Alanstormdotcom_Helloworld_IndexController dispatching with action [index]

You’ll also see a message whenever Magento can’t make a Module, Controller, or Action Method match, which is useful when debugging 404 problems.

Like this article? Then you’ll love Commerce Bug, the must have debugging extension for anyone using Magento. Whether you’re just starting out or you’re a seasoned pro, Commerce Bug will save you and your team hours everyday. Grab a copy and start working with Magento instead of against it.

Originally published September 20, 2009
Series Navigation<< Magento Development EnvironmentMagento Configuration Lint >>