简体   繁体   English

Magento:阻止替代会阻止phtml显示

[英]Magento: Block override stops phtml from displaying

I'm working on a Magento project and I've overridden the Page Html Header block because I need to change how the getLogoSrc() function (which I found in app/code/core/Mage/Page/Block/Html/Header.php). 我正在研究Magento项目,并且已覆盖Page Html Header块,因为我需要更改getLogoSrc()函数的方式(我在app / code / core / Mage / Page / Block / Html / Header中找到了此函数getLogoSrc() 。 php)。 However I seem to have done something incorrectly as header.phtml is no longer being drawn. 但是我似乎做错了什么,因为header.phtml不再被绘制。

app/code/local/NameSpace/Customize/Block/Html/Header.php 应用程序/代码/本地/ NameSpace /自定义/块/HTML/Header.php

class NameSpace_Page_Block_Html_Header extends Mage_Page_Block_Html_Header
{
    ...Code...
}

app/code/local/NameSpace/Customize/etc/config.xml app / code / local / NameSpace / Customize / etc / config.xml

<config>
    <modules>
        <NameSpace_Customize>
            <version>0.1.0</version>
        </NameSpace_Customize>
    </modules>
    <helpers>
        <customize>
            <class>NameSpace_Customize_Helper</class>
        </customize>
    </helpers>
    <global>
        <blocks>
            <page>
                <rewrite>
                    <html_header>NameSpace_Page_Block_Html_Header</html_header>
                </rewrite>
            </page>
        </blocks>
    </global>
</config>

app/etc/modules/NameSpace_Customize.xml app / etc / modules / NameSpace_Customize.xml

<config>
    <modules>
        <NameSpace_Customize>
            <active>true</active>
            <codePool>local</codePool>
        </NameSpace_Customize>
    </modules>
</config> 

When I remove everything inside of the <global> tags in config.xml the header is displayed correctly. 当我删除config.xml中<global>标记内的所有内容时,标题将正确显示。

This is my first Magento project so I may have gone about this the wrong way. 这是我的第一个Magento项目,所以我可能做错了方法。 Any input would be appreciated. 任何输入将不胜感激。

Thanks 谢谢

The block class name must match the folder it is in. 块类名称必须与它所在的文件夹匹配。

class NameSpace_Customize_Block_Html_Header extends Mage_Page_Block_Html_Header
{
    // do not write any more in here until you've tested at least once
}

Make the equivalent change in config.xml too. 同样在config.xml中进行相同的更改。 Also the <helpers> node must be inside the <global> node. 同样, <helpers>节点也必须位于<global>节点内。

<config>
    <modules>
        <NameSpace_Customize>
            <version>0.1.0</version>
        </NameSpace_Customize>
    </modules>
    <global>
        <helpers>
            <customize>
                <class>NameSpace_Customize_Helper</class>
            </customize>
        </helpers>
        <blocks>
            <page>
                <rewrite>
                    <html_header>NameSpace_Customize_Block_Html_Header</html_header>
                </rewrite>
            </page>
        </blocks>
    </global>
</config>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM