Search code examples
debugginglayoutmagentoblock

Magento controller action


Okay, very precisely, I've been tasked with a Magento admin module that doesn't involve layouts, blocks or views. Nothing is ever to be displayed. However, when I call an action in my module's adminhtml controller, Magento keeps trying to render a layout and failing that, redirects to the Dashboard with a "Failed to load source for: http://www.example.com/index.php/admin/modulename/adminhtml_index/actioname" blah, blah, blah.

Now, I've looked at FireBug's Net output for a familiar system action like clearing the cache like so: http://www.example.com/index.php/admin/cache/flushSystem/key/88848f202df8f254b3db13762ad7e949/ and this too responds with "Failed to load source for: http://www.example.com/index.php/admin/cache/flushSystem/key/88848f202df8f254b3db13762ad7e949/"

First of all, this has to be a controller that extends Mage_Adminhtml_Controller_Action because otherwise I can't tell if the admin is logged in and has permission to action my controller. Second of all, I don't have a debugging system (and my company's to cheap to spend any money on software engineering) so I have to cave man debug. So my question is, how on earth do debug my code and get output from Magento without loading a layout and rendering blocks? I've tried to output in the predispatch method and exiting before the predispatch ends and this WORKS, but I would prefer not to do any coding in predispatch. Any help would be greatly appreciated.


Solution

  • When Firebug says "Failed to load source" it means there is no data to display, typically during a 302 redirect. In a redirection only headers are sent and no body. This matches what you are experiencing.

    Secondly your URL contains admin/modulename/adminhtml_index/actionname which has four parts. In Magento there should only be three parts like "router/controller/action", which part is extra in yours?

    When you have the right action firing don't call $this->loadLayout()->renderLayout() because that would, um, load the layout. To output any other content use:

    $this->getResponse()->setBody($content);