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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 R语言卸载之后无法重装,显示电脑存在下载某些较大二进制文件行为,怎么办
  • ¥15 java 的protected权限 ,问题在注释里