Magento Custom Module, Fatal error: Call to a member function setFormAction()


When I hit my module on this url http://localhost/xxx/index.php/TradeEnquiry I get this error

Fatal error: Call to a member function setFormAction() on a non-object in C:\wamp\www\stockdisplays\app\code\local\Stock\Tradeenquiry\controllers\IndexController.php on line 55

Line 55 is this:

            ->setFormAction( Mage::getUrl('*/*/post') );

this is a fragment from my layout xml:

    <reference name="footer_links">
        <action method="addLink" translate="label title" module="tradeenquiry">
                <label>Trade Enquiry</label>
                <title>Trade Enquiry</title>

    <reference name="root">
        <action method="setTemplate"><template>page/2columns-right.phtml</template></action>
        <action method="setHeaderTitle" translate="title" module="tradeenquiry"><title>Trade Enquiry</title></action>
    <reference name="content">
        <block type="core/template" name="tradeenquiryView" template="tradeenquiry/view.phtml"/>

I dont get what the problem is? the block is correctly named 'tradeenquiryView'. The only thing I can think of is that the layout xml is cached somehow? As I have to hit the module on /TradeEnquiry and not /tradeenquiry like I have stated in my layout xml, so its almost as if its using an older version?

7/8/2009 7:38:22 PM

Like everything Magento, there's a numerous reasons this could be happening.

First, I'd avoid using a capital letter "V" when naming your blocks. Although I don't think this would cause a problem (as names are references to URIs (core/textlist, etc.) and template filepath (/path/to/template.phtml)), there's a de-facto naming convention in the layout system of lowercase/underscore names which someone, somewhere (i.e Varien) may decide is an enforced convention.

Second, have you called


in your controller action before the line where you attempt to set the form action? Until you do this your Layout object won't have instantiated and/or have a reference to your block objects, which means


will always return false.

Other debugging tips. Try the following to make sure you're getting back the classes you think you should.


Finally, if all that fails, go to the source of the layout object


And take a look at the getBlock method

public function getBlock($name)
    if (isset($this->_blocks[$name])) {
        return $this->_blocks[$name];
    } else {
        return false;

and start throwing in debug statements to see if you can figure out why the system isn't returning a reference to your block. Don't forget to remove/not-check-in your debugging statements as this is core system code.

7/8/2009 7:21:59 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow