douzhuanfen5923 2014-08-11 22:14
浏览 16
已采纳

Magento:阻止覆盖阻止phtml显示

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). However I seem to have done something incorrectly as header.phtml is no longer being drawn.

app/code/local/NameSpace/Customize/Block/Html/Header.php

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

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

<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.

This is my first Magento project so I may have gone about this the wrong way. Any input would be appreciated.

Thanks

  • 写回答

1条回答 默认 最新

  • douvcpx6526 2014-08-11 22:44
    关注

    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. Also the <helpers> node must be inside the <global> node.

    <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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器