【发布时间】:2018-11-01 11:55:21
【问题描述】:
我是 Magento 初学者,在创建新的自定义块方面需要帮助。 基本上我只希望块在被调用时显示“你好”。
-
模块安装xml文件,app/etc/modules/MyExtensions_HelloBlock.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <MyExtensions_HelloBlock> <active>true</active> <codePool>local</codePool> </MyExtensions_HelloBlock> </modules> </config> -
模块配置xml文件,app/code/local/MyExtensions/HelloBlock/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?> <config> <modules> <MyExtensions_HelloBlock> <version>0.0.1</version> </MyExtensions_HelloBlock> </modules> <global> <blocks> <helloblock> <class>MyExtensions_HelloBlock_Block</class> </helloblock> </blocks> </global> </config> -
块类,app/code/local/MyExtensions/HelloBlock/Hello.php
<?php class MyExtensions_HelloBlock_Block_Hello extends Mage_Core_Block_Template { public function hello() { echo "hello"; } } ?> -
块的模板文件,app/design/frontend/default/default/template/helloblock/hello.phtml
<?php $this->hello(); ?>
然后我在模板“app/design/frontend/venedor/default/template/page/1column.phtml”中这样调用我的新块:
echo $this->getLayout()->createBlock('helloblock/hello')->setTemplate('helloblock/hello.phtml')->toHtml();
结果:
致命错误:在布尔值中调用成员函数 setTemplate() /app/design/frontend/venedor/default/template/page/1column.phtml 第 58 行
我关注了这个tutorial。
【问题讨论】:
-
老兄,块文件应该在“块”目录中,app/code/local/MyExtensions/HelloBlock/Block/Hello.php
标签: magento magento-1.8