Magento No Frills Layouts以编程方式不起作用Magento 1.8.1

时间:2014-01-27 12:23:43

标签: magento

我正在尝试处理布局,并遇到了Alan Storm的书Nofrills Magento Layouts(好书)。

我已经完成了第19页的示例,在“高级块功能”部分下添加了一个新类。

我已根据示例创建了所有文件和模板,但我现在收到错误,并且在修复之前似乎无法进展。

块类看起来像这样:

<?php
class Nofrills_Booklayout_Block_Helloworld extends Mage_Core_Block_Template
{
public function _construct()
{
        $this->setTemplate('helloworld.phtml');
        return parent::_construct();    
}
}
?>

IndexController类如下所示:

<?php
class Nofrills_Booklayout_IndexController  extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
    $block_1 = new Mage_Core_Block_Text();
    $block_1->setText('Original Text');

    $block_2 = new Mage_Core_Block_Text();
    $block_2->setText('The second sentence');

    $main_block = new Nofrills_Booklayout_Block_Helloworld();
    //$main_block->setTemplate('../helloworld.phtml');

    $main_block->setChild('the-first',$block_1);
    $main_block->setChild('the-second', $block_2);

    //$block_1->setText('Wait, I want this text instead!');
    echo $main_block->toHtml();

}

    public function helloblockAction()
{
    $block_1 = new Mage_Core_Block_Text();
    $block_1->setText('Original Text');

    $block_2 = new Mage_Core_Block_Text();
    $block_2->setText('The second sentence');

    $main_block = new Nofrills_Booklayout_Block_Helloworld();
    //$main_block->setTemplate('helloworld.phtml');

    $main_block->setChild('the-first',$block_1);
    $main_block->setChild('the-second', $block_2);

    echo $main_block->toHtml();

}
}

,模板如下所示:

<h1>hello world</h1>
<p>
<?php echo $this->getChildHtml('the-first'); ?>
</p><p>
<?php echo $this->getChildHtml('the-second'); ?>
</p>

然而,当我转到我的网址来呼叫该页面时:

http://www.phmagento.com/nofrills_booklayout/index/index
http://www.phmagento.com/nofrills_booklayout/index/helloblock

I get this error which is totally confusing me:

Warning: include(C:\xampp\htdocs\phmagento\includes\src\Nofrills_Booklayout_Block_Helloworld.php): failed to open stream: No such file or directory  in C:\xampp\htdocs\phmagento\includes\src\Varien_Autoload.php on line 93
#0 C:\xampp\htdocs\phmagento\includes\src\Varien_Autoload.php(93): mageCoreErrorHandler(2, 'include(C:\xamp...', 'C:\xampp\htdocs...', 93, Array)
#1 C:\xampp\htdocs\phmagento\includes\src\Varien_Autoload.php(93): Varien_Autoload::autoload()
#2 [internal function]: Varien_Autoload->autoload('Nofrills_Bookla...')
#3 C:\xampp\htdocs\phmagento\app\code\local\Nofrills\Booklayout\controllers\IndexController.php(12): spl_autoload_call('Nofrills_Bookla...')
#4 C:\xampp\htdocs\phmagento\includes\src\__default.php(13969): Nofrills_Booklayout_IndexController->indexAction()
#5 C:\xampp\htdocs\phmagento\includes\src\__default.php(18331): Mage_Core_Controller_Varien_Action->dispatch('index')
#6 C:\xampp\htdocs\phmagento\includes\src\__default.php(17865): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#7 C:\xampp\htdocs\phmagento\includes\src\__default.php(20465): Mage_Core_Controller_Varien_Front->dispatch()
#8 C:\xampp\htdocs\phmagento\app\Mage.php(684): Mage_Core_Model_App->run(Array)
#9 C:\xampp\htdocs\phmagento\index.php(87): Mage::run('', 'store')
#10 {main}

如果有人有任何关于我为什么会收到此错误或我做错了什么的线索,我们将不胜感激。

非常感谢 格雷厄姆

1 个答案:

答案 0 :(得分:0)

自动加载器正在尝试从Nofrills_Booklayout_Block_Helloworld加载C:\xampp\htdocs\phmagento\includes\src\Nofrills_Booklayout_Block_Helloworld.php类。你确定该文件存在吗?它应该包含第一个代码段中的块。