我是Magento的新手,我正在尝试为我构建的模块制作布局.我有一个简单的模块和一个输出'Hello World'的IndexController(我已经使用了本教程).
现在我想为该模块制作一个布局,我已经使用了本教程,但它不起作用.有人能指点我一个教程或者可以解释一下Magento中的布局是如何工作的吗?
谢谢 :)
这是我到目前为止所做的:我有一个名为'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>
Run Code Online (Sandbox Code Playgroud)
这是Andrei_Helloworld模块:
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Andrei_Helloworld>
<active>true</active>
<codePool>local</codePool>
</Andrei_Helloworld>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
这是我的控制器:
class Andrei_Helloworld_IndexController extends Mage_Core_Controller_Front_Action
{
public function indexAction()
{
echo 'Hello world';
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我到目前为止所做的一切.该模块正常工作.我想要一个我的IndexController的布局.谢谢 :)
OSd*_*ave 21
所以,有些东西丢失了......
在config.xml中声明布局更新:
<frontend>
...
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
...
</frontend>
Run Code Online (Sandbox Code Playgroud)在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>
Run Code Online (Sandbox Code Playgroud)在xml布局文件中创建你刚刚设置为模板的phtml文件,即app/design/frontend/base/default/template/helloworld.phtml:
this is the content of helloworld.phtml
Run Code Online (Sandbox Code Playgroud)加载并渲染所有这些内容,在控制器的操作中,将echo语句替换为:
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
Run Code Online (Sandbox Code Playgroud)| 归档时间: |
|
| 查看次数: |
10788 次 |
| 最近记录: |