我是Magento的新手,我正在尝试为我构建的模块制作布局。我有一个简单的模块和一个输出'Hello World'的IndexController。(我使用this教程)。
现在我想为该模块制作一个布局,我已经使用了这个tutorial,但它不起作用。有人可以指点我的教程或者可以解释一下布局在Magento中的工作原理吗?
Thx:)
这是我到目前为止所做的事情: 我有一个名为'Andrei'的包和一个'Hello World'模块。
以下是我的模块的config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<version>0.1.0</version>
</Andrei_Helloworld>
</modules>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>Andrei_Helloworld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
</frontend>
</config>
这是Andrei_Helloworld模块:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<active>true</active>
<codePool>local</codePool>
</Andrei_Helloworld>
</modules>
</config>
这是我的控制器:
class Andrei_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Hello world';
}
}
这是我到目前为止所做的一切。该模块正常工作。我想要一个我的IndexController的布局。谢谢:)
答案 0 :(得分:21)
所以,有些东西不见了......
在config.xml中声明布局更新:
<frontend>
...
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
...
</frontend>
在 app / design / frontend / base / default / layout / helloworld.xml 中创建布局xml文件,然后在其中创建对模块/控制器/操作的引用:
<?xml version="1.0"?>
<layout>
<helloworld_index_index>
<reference name="content">
<block type="core/template" name="helloworld" template="helloworld.phtml" />
</reference>
</helloworld_index_index>
</layout>
在xml布局文件中创建您刚刚设置为模板的phtml文件,即 app / design / frontend / base / default / template / helloworld.phtml :
this is the content of helloworld.phtml
加载并渲染所有这些内容,在控制器的操作中,将echo
语句替换为:
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}