Question

I have a custom Block which I'm now trying to break into two sepparate blocks.

Here's my folder structure (on app/code/local/MyNamespace/CustomerDashboard):

enter image description here

Since I want to break the functions of this module into two smaller parts I added the files MyMenu.php on Block folder, and MyMenuController.php into controllers.

Then, I just copy/pasted the code from Deliverydetails.php into MyMenu.php and DeliverydetailsController.phpinto MyMenuController.php just to see if it would work.

I went into my local.xml and added the reference to my module and it's template:

<reference name="left">
        <block type="customerdashboard/mymenu" name="customerdashboard.mymenu" template="customer/form/my-menu.phtml"/>
    </reference>

When I access the page where I should be seeing the content, there is nothing in the place where the module should be, but I went to check on the exceptions.log and found this:

exception 'Mage_Core_Exception' with message 'Invalid block type: MyNamespace_CustomerDashboard_Block_Mymenu' in /var/www/html/mysite/public_html/app/Mage.php:595
Stack trace:
#0 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block type...')
#1 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('customerdashboa...', Array)
#2 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('customerdashboa...', 'customerdashboa...')
#3 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('customerdashboa...', 'customerdashboa...')
#4 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(205): Mage_Core_Model_Layout->_generateBlock(Object(Mage_Core_Model_Layout_Element), Object(Mage_Core_Model_Layout_Element))
#5 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 /var/www/html/mysite/public_html/app/code/core/Mage/Customer/controllers/AccountController.php(107): Mage_Core_Controller_Varien_Action->loadLayout()
#9 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Customer_AccountController->indexAction()
#10 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#11 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#12 /var/www/html/mysite/public_html/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#13 /var/www/html/mysite/public_html/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#14 /var/www/html/mysite/public_html/index.php(93): Mage::run('', 'store')
#15 {main}

I didn't touch my config.xml nor anything else aside from the two files I already mentioned (and only to remove functionality I didn't want in this particular block) and this is my config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <MyNamespace_CustomerDashboard>
                <version>0.1.1</version>
        </MyNamespace_CustomerDashboard>
    </modules>   

    <global>
        <helpers>
            <customerdashboard>
                <class>MyNamespace_CustomerDashboard_Helper</class>
            </customerdashboard>
        </helpers>
        <blocks>
            <customerdashboard>
                <class>MyNamespace_CustomerDashboard_Block</class>
            </customerdashboard>
        </blocks>
        <sales>
            <order>
                <states>
                    <invoiced translate="label">
                        <label>Invoiced</label>
                        <statuses>
                            <invoced default="1"/>
                        </statuses>
                        <visible_on_front>1</visible_on_front>
                    </invoiced>
                </states>
            </order>
        </sales>
    </global>

    <frontend>
        <routers>
            <customerdashboard>
                <use>standard</use>
                <args>
                    <module>MyNamespace_CustomerDashboard</module>
                    <frontName>customerdashboard</frontName>
                </args>
            </customerdashboard>
        </routers>  
    </frontend>     

</config>

I've read other threads on this matter here on StackExchange but didn't get any clues to what might be the problem.

So, what am I doing wrong that I can't get my block to render and I'm getting that error on my exceptions.log ? Also, I'm a Magento newb.

Was it helpful?

Solution

As per as magento,the file/folder name after Block,Model,Helper folder should be start with Uppercase and only contain one uppercase for each folder and files.

According to magento the file name is Mymenu instead of MyMenu.

Class name should be MyNamespace_CustomerDashboard_Block_Mymenu

OTHER TIPS

Your error says, it cant find the block MyNamespace_CustomerDashboard_Block_Mymenu. As per this hint, Your block class should be at app\code\local\MyNamespace\CustomerDashboard\Block\Mymenu.php. Please note you have MyMenu.php. It should be Mymenu.php. Also you need to ensure the class name is MyNamespace_CustomerDashboard_Block_Mymenu.

or

you can avoid this error by simply changing your local.xml update. It should look like this.

<reference name="left">
    <block type="customerdashboard/myMenu" name="customerdashboard.mymenu" template="customer/form/my-menu.phtml"/>
</reference>

See the type now we are using. It is customerdashboard/myMenu instead of customerdashboard/mymenu. Now this type will refer to the block class MyNamespace_CustomerDashboard_Block_MyMenu. This way your block will be recongnized by Magento and problem will resolve

Note : Dont forget to clear the cache.

In some cases (Magento 1.9), if we forgot to use construct function in block PHP file then put it and the issue will be fixed:

 protected function _construct()
    {
        parent::_construct();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top