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)

我试图做一个覆盖块的例子。 我以为我正确地遵循了说明,但没有任何反应。 某处有错误吗? p>

要覆盖的块是 Mage_Page_Block_Html_Head strong>。 我在config.xml中重写了块: p> \ n

 &lt; config&gt; 
&lt; blocks&gt; 
&lt; html&gt; 
&lt; rewrite&gt; 
&lt; head&gt; Hello_Mymodule_Block_Head&lt; / head&gt; 
&lt; / rewrite&gt; \  n&lt; / html&gt; 
&lt; / blocks&gt;  
&lt; / config&gt; 
  code>  pre> 
 
 

然后我创建了Head.php:app - code - local - Hello - Mymodule - Block - Head.php。 p>

我将原始Head.php中的getTitle方法复制到我的新Head.php中,然后我只是输入“die()”来查看它是否有效: p> \ n

 类Hello_Mymodule_Block_Head扩展Mage_Page_Block_Html_Head {
public function getTitle()
 {
 die(); 
 if(empty($ this-&gt; _data ['title'])){
 $  this-&gt; _data ['title'] = $ this-&gt; getDefaultTitle(); 
} 
返回strtoupper(htmlspecialchars(html_entity_decode(trim($ this-&gt; _data ['title']),ENT_QUOTES,'  UTF-8'))); 
}} 
  code>  pre> 
 
 

没有任何反应,我不知道如何搜索错误。 我的模块处于活动状态并正常工作(它显示在管理员中) p> div>

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>