Why is Magento trying to call in the Mage namespace rather than my custom namespace?


Question

I’ve created a module within the local code folder in our custom namespace. The block isn’t displaying on the frontend, and on checking the exception log, it turns out Magento is looking in the wrong place.

exception ‘Mage_Core_Exception’ with message ‘Invalid block type:
Mage_MyCompany_ForthcomingProducts_Block_List’
in /var/www/html/app/Mage.php:407

The same also goes if I exclude the MyCompany_ prefix when calling the block; it still looks in the Mage namespace. I have this in a file called MyCompany_All.xml in the modules folder, and the CMS layouts I’ve added are working fine, so Magento is definitely loading it:

<?xml version="1.0"?>
<config>
    <modules>
        <MyCompany_CmsLayouts>
            <codePool>local</codePool>
            <active>true</active>
        </MyCompany_CmsLayouts>
        <MyCompany_ForthcomingProducts>
            <codePool>local</codePool>
            <active>true</active>
        </MyCompany_ForthcomingProducts>
    </modules>
</config>

Does anyone have any ideas as to what’s causing this?


Added: The block is being called by a static block with this template code:

{{block type="MyCompany_ForthcomingProducts/List" template="forthcomingproducts/list.phtml"}}

And the config.xml for the block is:

<?xml version="1.0" encoding="utf-8"?>
    <config>
        <modules>
            <MyCompany_ForthcomingProducts>
                <version>0.9</version>
            </MyCompany_ForthcomingProducts>
        </modules>

        <global>
            <blocks>
                <forthcomingproducts>
                    <class>MyCompany_ForthcomingProducts_Block</class>
                </forthcomingproducts>
            </blocks>
       </global>
    </config>
1
9
5/30/2012 12:43:18 PM

Accepted Answer

Try adjusting your block declaration as follows:

{{block type="forthcomingproducts/list" template="forthcomingproducts/list.phtml"}}

In your config file you defined an alias for your blocks (forthcomingproducts) and now you should follow it. Magento will dereference forthcomingproducts to be MyCompany_ForthcomingProducts_Block as you requested, then append the capitalized class name (list), creating the classname MyCompany_ForthcomingProducts_Block_List. When you use a alis that Magento doesn't know about (MyCompany_ForthcomingProducts in your example), it is assumed to be part of the Mage namespace.

Hope that helps, Joe

8
1/28/2010 4:05:25 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon