【发布时间】:2014-11-24 01:03:39
【问题描述】:
这是一个基本问题,但过去几天让我失眠。
我编写了一个带有控制器、phtml 模板和块类的自定义模块,如下所示: app/code/local/Huahan/HelloWorld/Block Helloworld.php(其中 Huahan_Helloworld_Block_Helloworld 扩展了 Mage_Core_Block_Template) app/code/local/Huahan/HelloWorld/controllers IndexController.php(其中定义了索引控制器的 indexAction) app/design/frontend/base/default/template/huahan/helloworld helloworld.phtml(定义视图的地方) 应用程序/设计/前端/基础/默认/布局 helloworld.xml(文件名“helloworld.xml”在etc/config.xml中指定)
我知道 Magento 中的每个请求处理都是从控制器及其操作方法开始的。
在布局helloworld.xml中,我在block标签中指定了模板文件
<helloworld_index_nihao>
<block type="core/template" name="just_an_arbitary_name" output="toHtml" template="huahan/helloworld/nihao.phtml"/>
</helloworld_index_nihao>
</layout>
因此控制器在处理请求时知道使用哪个模板。
问题是如何让 Magento 知道 Huahan_Helloworld_Block_Helloworld 是我希望它在渲染任何输出之前加载的块类?
如果有任何关于 Magento xml 的详细文档?我总是对 Magento xml 语法的复杂性和随意性感到沮丧
Magento的版本是ver.1.9.0.1
config.xml如下
<?xml version="1.0"?>
<config>
<modules>
<huahan_helloworld>
<version>
0.1.0
</version>
</huahan_helloworld>
</modules>
<frontend>
<routers>
<!-- the <helloworld> tagname appears to be arbitrary, but by
convention is should match the frontName tag below-->
<helloworld>
<use>standard</use>
<args>
<module>Huahan_HelloWorld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
</frontend>
<global>
<blocks>
<helloworld>
<class>Huahan_Helloworld_block</class>
</helloworld>
</blocks>
</global>
</config>
提前致谢。非常感谢您在此处阅读。
【问题讨论】:
标签: php magento zend-framework