【问题标题】:Magento Instead of displaying my Block Popular Tags block shows up from default themeMagento 而不是显示我的块热门标签块从默认主题显示
【发布时间】:2014-10-08 10:10:44
【问题描述】:

我一直在我的自定义模块中处理 magento 块。一切正常,控制器正常,其余工作正常。我面临的问题是我的块没有按预期显示。不是显示我的块或块消息,而是显示“流行标签”块。这是我的模块 Experiment/Test/etc/config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>

    <modules>
        <experiment_test>
            <vresion>0.0.1</vresion>
        </experiment_test>
    </modules>

    <frontend>
        <global>
            <blocks>
                <experiment>
                    <class>Experiment_Test_Block</class>
                </experiment>
            </blocks>
        </global>
        <routers>
            <experiment>
                <use>standard</use>
                <args>
                    <module>Experiment_Test</module>
                    <frontName>experiment</frontName>
                </args>
            </experiment>
            <layout>
                <updates>
                    <experiment>
                        <file>experiment.xml</file>
                    </experiment>
                </updates>
            </layout>
        </routers>
    </frontend>

</config>

我的模块配置文件是 app/etc/modules/Experiment_Test.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Experiment_Test>
            <active>true</active>
            <codePool>local</codePool>
        </Experiment_Test>
    </modules>
</config>

这是我的 Experiment/Test/controllers/IndexController.php:

<?php
class Experiment_Test_IndexController extends Mage_Core_Controller_Front_Action
{

    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
    }

}
?>

这是我的方块位置:Experiment/Test/Block/ExpBl​​ock.php:

<?php
class Experiment_Test_Block_Expblock extends Mage_Core_Block_Template {
    public function methodblock(){
        return 'Information About my Block!!';
    }
}
?>

这是我放置在 design/frontend/mytheme/default/layout/experiment.xml 中的布局文件:

<?xml version="1.0"?>
<layout version="0.0.1">

    <default>
        <reference name="content"></reference>
    </default>

    <experiment_index_index>
        <reference name="content">
            <block type="test/expblock" name="afficher_expbloc" template="experiment/afficher.phtml" />
        </reference>
    </experiment_index_index>

</layout>

这是我放置在 design/frontend/mytheme/default/template/experiment/afficher.phtml 中的模板文件:

<?php echo $this->methodblock(); ?>

但输出显示来自另一个块,即来自流行标签块和 frontend/base/default/template/tag/popular.phtml

请让我知道我在哪里犯了错误。

【问题讨论】:

  • 尝试将您的 experminet.xml 插入 app/design/adminhtml/default/default/layout 以查看是否有帮助
  • 然后刷新缓存

标签: php xml magento


【解决方案1】:

你的布局文件中有一个错误的块定义

<block type="test/expblock" name="afficher_expbloc" template="experiment/afficher.phtml" />

这是错误的。而不是这个,你需要使用这个

 <block type="experiment/expblock" name="afficher_expbloc" template="experiment/afficher.phtml" />

experiment 是您通过config.xml 文件设置的块唯一标识符名称。为了指向您的Experiment_Test_Block_Expblock,您需要在布局文件中为您的自定义块使用experiment/expblock 类型。

【讨论】:

  • 感谢您的更正,但仍无法按预期显示。
  • 您是否从您的块中收到消息并在前端输出?
【解决方案2】:

好吧,我在深入了解之后自己找到了解决方案,那就是我在我的 config.xml 文件(Experiment/Test/etc/config.xml)中声明了一些错误的标签 - 所以我想分享一下对遇到相同情况的人有所帮助:这是我更正的 config.xml:

<?xml version="1.0" encoding="UTF-8"?>
<config>

    <modules>
        <experiment_test>
            <vresion>0.0.1</vresion>
        </experiment_test>
    </modules>

    <frontend>

        <routers>
            <experiment>
                <use>standard</use>
                <args>
                    <module>Experiment_Test</module>
                    <frontName>experiment</frontName>
                </args>
            </experiment>

        </routers>
        <layout>
            <updates>
                <experiment>
                    <file>experiment.xml</file>
                </experiment>
            </updates>
        </layout>
    </frontend>

    <global>
        <blocks>
            <experiment>
                <class>Experiment_Test_Block</class>
            </experiment>
        </blocks>
    </global>

</config>

我的布局文件也有问题,@programmer_rkt 回答了这个问题

【讨论】:

    【解决方案3】:

    你的代码有很多问题:

    第一个 config.xml

    experiment_test 应该是Experiment_Test

    来自

       <modules>
            <experiment_test>
                <vresion>0.0.1</vresion>
            </experiment_test>
        </modules>
    

     <modules>
            <Experiment_Test>
                <vresion>0.0.1</vresion>
            </Experiment_Test>
        </modules>
    

    文件名ExpBlock.php应该是Expblock.php

    并改变:

     <block type="test/expblock" name="afficher_expbloc" template="experiment/afficher.phtml" />
    

    &lt;block type="tag/popular" name="tags_popular" template="tag/popular.phtml"/&gt;

    【讨论】:

    • 不,这很好,它使用这个.. 所以这不是问题,尽管 config.xml 中有问题 - 我发现并在这里分享。谢谢
    猜你喜欢
    • 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
    相关资源
    最近更新 更多