当我在这个网址http://localhost/xxx/index.php/TradeEnquiry上点击我的模块时,我收到此错误
Fatal error: Call to a member function
setFormAction() on a non-object in
C:wampwwwstockdisplaysappcodelocalStockTradeenquirycontrollersIndexController.php
on line 55
第55行是这样的:
<code> $this->getLayout()->getBlock('tradeenquiryView')
->setFormAction( Mage::getUrl('*/*/post') );
</code>
这是我的布局xml中的一个片段:
<code><default>
<reference name="footer_links">
<action method="addLink" translate="label title" module="tradeenquiry">
<label>Trade Enquiry</label>
<url>tradeenquiry</url>
<title>Trade Enquiry</title>
<prepare>true</prepare>
</action>
</reference>
</default>
<tradeenquiry_index_index>
<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>
<reference name="content">
<block type="core/template" name="tradeenquiryView" template="tradeenquiry/view.phtml"/>
</reference>
</tradeenquiry_index_index>
</code>
我不知道问题是什么?该块正确命名为“tradeenquiryView”.我唯一能想到的是布局xml以某种方式缓存?因为我必须点击/ TradeEnquiry上的模块而不是像我在布局xml中所说的那样/ tradeenquiry,所以它几乎就像它使用旧版本一样?
解决方法:
像Magento一样,有很多原因可能会发生.
首先,在命名块时我会避免使用大写字母“V”.虽然我不认为这会导致问题(因为名称是对URI(核心/文本列表等)和模板文件路径(/path/to/template.phtml)的引用),但是在事实上这是一个事实上的命名约定.某个地方(即Varien)可能决定的小写/下划线名称的布局系统是强制约定.
第二,你有没有打过电话
<code>$this->loadLayout(); </code>
在您尝试设置表单操作的行之前的控制器操作中?在您执行此操作之前,您的Layout对象将不会实例化和/或具有对块对象的引用,这意味着
<code>$this->getLayout()->getBlock('...')
</code>
总是会返回false.
其他调试技巧.请尝试以下操作以确保您获得了您认为应该的课程.
<code>die(get_class($this->getLayout()->getBlock('root')));
die(get_class($this->getLayout()));
</code>
最后,如果全部失败,请转到布局对象的源
<code>app/code/core/Mage/Core/Model/Layout.php </code>
并看一下getBlock方法
<code>public function getBlock($name)
{
if (isset($this->_blocks[$name])) {
return $this->_blocks[$name];
} else {
return false;
}
}
</code>
并开始抛出调试语句,看看你是否可以找出系统没有返回对块的引用的原因.不要忘记删除/不签入调试语句,因为这是核心系统代码.
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!