【问题标题】:How to display pages in magento如何在magento中显示页面
【发布时间】:2012-04-30 14:09:03
【问题描述】:

我刚开始学习 magento。我在这里找到了一个示例 helloworld 模块代码:

http://www.engineer-ing.com/writing-magento-extension-part1/part2

我这里使用的控制器代码是:

 //app/code/local/Magentotutorial/Helloworld/controllers/IndexController.php
class Magentotutorial_Helloworld_IndexController extends Mage_Core_Controller_Front_Action {        

    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
        echo 'Hello Index!';
    }

config.xml 代码:

//app/code/local/Magentotutorial/Helloworld/etc/config.xml
<config>    
    <modules>
        <Magentotutorial_Helloworld>
            <version>0.1.0</version>
        </Magentotutorial_Helloworld>
    </modules>
    <frontend>
        <routers>
            <helloworld>
                <use>standard</use>
                <args>
                    <module>Magentotutorial_Helloworld</module>
                    <frontName>helloworld</frontName>
                </args>
            </helloworld>
        </routers>  
        <layout>
            <updates>
                <helloworld>
                      <file>helloworld.xml</file>
                </helloworld>
            </updates>
        </layout>
     </frontend>
</config>

helloworld.xml 代码

//app/design/frontend/default/default/layout/helloworld.xml
<?xml version="1.0"?>
    <layout version="0.1.0">
        <helloworld_index_index>
            <default>
                <reference name="content">
                     <block type="page/html" name="helloworld" output="toHtml" template="helloworld/helloworld.phtml"/>
                </reference>
            </default>
        </helloworld_index_index>
    </layout>

HelloWorld.php

class Magentotutorial_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template
{
  public function getContent()
     {
         return ‘informations about my block !!’ ;
     }
}

在 helloworld.phtml 中,我只需键入一个字符串,例如“hello world to all of u”。

它没有显示任何错误。但是页面上没有显示任何内容。

我不知道我在哪里做错了。有人可以帮我解决显示页面的问题

【问题讨论】:

  • 将这两行添加到您的 .htaccess 文件中:SetEnv MAGE_IS_DEVELOPER_MODE 和 php_flag display_errors 1
  • 教程的链接是404。你不使用HelloWorld.php中的块,是吗?在此代码部分中,您有“wordpress 风格的撇号”(因为 C&P?)。将它们替换为正常的 '.也许这是解决方案的一部分。

标签: php magento magento-1.5


【解决方案1】:

您在布局 XML 中的错误。你不需要&lt;default&gt;节点见下文

<?xml version="1.0"?>
<layout version="0.1.0">
    <helloworld_index_index>
        <reference name="content">
             <block type="page/html" name="helloworld" output="toHtml" template="helloworld/helloworld.phtml"/>
        </reference>
    </helloworld_index_index>
</layout>

关于块,我不确定你的构造是否可以工作,如果没有,请尝试将其替换为:

<block type="core/template" name="helloworld" template="helloworld/helloworld.phtml"/>

你忘了在 config.xml 中声明块,见下文:

<global>
    <blocks>
        <helloworld>
            <class>Magentotutorial_HelloWorld_Block</class>
        </helloworld>
    </blocks>
</global>

在此之后你可以使用下一个块声明:

<block type="helloworld/helloworld" name="helloworld" template="helloworld/helloworld.phtml"/>

希望这会有所帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多