douhuigang9550 2015-09-05 20:51
浏览 45
已采纳

Magento - 覆盖块

I trying to do an example of overriding a block. I thought I followed the instructions correctly, but nothing happens. Is there an error somewhere?

The block to be overwritten is Mage_Page_Block_Html_Head. I do the rewrite of the block in config.xml:

<config>
   <blocks>
        <html>
            <rewrite>
                <head>Hello_Mymodule_Block_Head</head>
            </rewrite>
        </html>
    </blocks>    
 </config>

Then I create Head.php in: app - code - local - Hello - Mymodule - Block - Head.php.

I copy the getTitle method from the original Head.php into my new Head.php, then I just put in "die()" to see if it works:

class Hello_Mymodule_Block_Head extends Mage_Page_Block_Html_Head {
public function getTitle()
{
    die();
    if (empty($this->_data['title'])) {
        $this->_data['title'] = $this->getDefaultTitle();
    }
    return strtoupper(htmlspecialchars(html_entity_decode(trim($this->_data['title']), ENT_QUOTES, 'UTF-8')));
}}      

Nothing happens, and I don't know how to search for the error. My module is active and working (it shows up in admin)

  • 写回答

1条回答 默认 最新

  • dsk88199 2015-09-05 21:14
    关注

    You have to rewrite block Mage_Page_Block_Html_Head but what you are trying to rewrite is Mage_Block_Html_Head which do not exist at all. change your confix xml to

    <config>
       <blocks>
            <page>
                <rewrite>
                    <html_head>Hello_Mymodule_Block_Head</html_head>
                </rewrite>
            </page>
        </blocks>    
     </config>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器