Search code examples
magentoblockextend

Error when extending a magento block


I'm trying to extend the defult magento welcome msg block, however I am met with an error:

exception 'Mage_Core_Exception' with message 'Invalid block type: ModuleNameSpace_Modulename_Block_Page_Html_Welcome' in /var/www/magento/project/app/Mage.php:595

Here's the relevant part of config xml for my module:

<config>
    <!-- -->
    <global>
        <blocks>
            <page>
                <rewrite>
                    <html_welcome>ModuleNameSpace_Modulename_Block_Page_Html_Welcome</html_welcome>
                </rewrite>
            </page>
        </blocks>
    </global>
</config>

And here's the extended class located in

/app/code/local/ModuleNameSpace/Modulename/Page/Block/Html/Welcome.php

<?php
class ModuleNameSpace_Modulename_Page_Block_Html_Welcome extends Mage_Page_Block_Html_Welcome
{

}
?>

Should any other information be required, just tell me. Thanks in advance.


Solution

  • you have to specify the class name of your block. i.e.,

    <global>
        <blocks>
            <modulename>
                <class>Mynamespace_Modulename_Block</class>
            </modulename>
        </blocks>
    </global>
    

    then you can call your block like

    <block type="modulename/some" template="some.phtml">
    

    Edit

    /app/code/local/ModuleNameSpace/Modulename/Page/Block/Html/Welcome.php

    Change your folder structure like this

    /app/code/local/ModuleNameSpace/Modulename/Block/Page/Html/Welcome.php

    add change the class name

    <?php
    class ModuleNameSpace_Modulename_Block_Page_Html_Welcome extends Mage_Page_Block_Html_Welcome
    {
    }
    ?>