我一直在关注No Frills Magento布局书。所有示例都正常工作,直到本节:
http://localhost/magento/nofrills_booklayout/index/layout
本地/ Nofrills / Booklayout的/ etc / config.xml中:
app/code/local/Nofrills/Booklayout/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Nofrills_Booklayout>
<version>0.1.0</version>
</Nofrills_Booklayout>
</modules>
<frontend>
<routers>
<nofrills_booklayout>
<use>standard</use>
<args>
<module>Nofrills_Booklayout</module>
<frontName>nofrills_booklayout</frontName>
</args>
</nofrills_booklayout>
</routers>
</frontend>
<global>
<blocks>
<nofrills_booklayout>
<class>Nofrills_Booklayout_Block</class>
</nofrills_booklayout>
</blocks>
<models>
<nofrills_booklayout>
<class>Nofrills_Booklayout_Model</class>
</nofrills_booklayout>
</models>
<helpers>
<nofrills_booklayout>
<class>Nofrills_Booklayout_Helper</class>
</nofrills_booklayout>
</helpers>
</global>
</config>
本地/ Nofrills / BookLayout /砌块/ HelloWorld.php:
<?php
class Nofrills_Booklayout_Block_HelloWorld extends Mage_Core_Block_Template
{
public function _construct()
{
$this->setTemplate('helloworld.phtml');
return parent::_construct();
}
public function _beforeToHtml()
{
$block_1 = new Mage_Core_Block_Text();
$block_1->setText('The first sentence. ');
$this->setChild('the_first', $block_1);
$block_2 = new Mage_Core_Block_Text();
$block_2->setText('The second sentence. ');
$this->setChild('the_second', $block_2);
}
public function fetchTitle()
{
return 'Hello Fancy World';
}
}
本地/ Nofrills / Booklayout /控制器/ IndexController.php:
public function layoutAction()
{
$layout = Mage::getSingleton('core/layout');
$block = $this->getLayout()->createBlock('nofrills_booklayout/helloworld');
echo $block->toHtml();
}
这让我:
Call to a member function toHtml() on a non-object in...
答案 0 :(得分:0)
试试这个:
public function layoutAction()
{
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('nofrills_booklayout/helloworld'));
$this->renderLayout();
}
答案 1 :(得分:0)
正如马吕斯在评论部分所说,改变&#34; helloworld&#34; to&#34; helloWorld&#34;让它成真。