Reputation: 27
I got this exception in log file when just create a simple hello world module.
exception 'Mage_Core_Exception' with message 'Invalid block type: MyCompanyName_HelloWorld_Block_Helloworld' in /var/www/magento1/app/Mage.php:595
Stack trace:
#0 /var/www/magento1/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /var/www/magento1/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('helloworld/hell...', Array)
#2 /var/www/magento1/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('helloworld/hell...', 'helloworld.hell...')
#3 /var/www/magento1/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('helloworld/hell...', 'helloworld.hell...')
#4 /var/www/magento1/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/magento1/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /var/www/magento1/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#7 /var/www/magento1/app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#8 /var/www/magento1/app/code/local/MyCompanyName/HelloWorld/controllers/IndexController.php(5): Mage_Core_Controller_Varien_Action->loadLayout()
#9 /var/www/magento1/app/code/core/Mage/Core/Controller/Varien/Action.php(418): MyCompanyName_HelloWorld_IndexController->indexAction()
#10 /var/www/magento1/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(250): Mage_Core_Controller_Varien_Action->dispatch('index')
#11 /var/www/magento1/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/magento1/app/code/core/Mage/Core/Model/App.php(354): Mage_Core_Controller_Varien_Front->dispatch()
#13 /var/www/magento1/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#14 /var/www/magento1/index.php(87): Mage::run('', 'store')
#15 {main}
config file etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<MyCompanyName_HelloWorld>
<version>0.0.1</version>
</MyCompanyName_HelloWorld>
</modules>
<global>
<blocks>
<helloworld>
<class>MyCompanyName_HelloWorld_Block</class>
</helloworld>
</blocks>
</global>
<frontend>
<routers>
<helloworld>
<use>standard</use>
<args>
<module>MyCompanyName_HelloWorld</module>
<frontName>helloworld</frontName>
</args>
</helloworld>
</routers>
<layout>
<updates>
<helloworld>
<file>helloworld.xml</file>
</helloworld>
</updates>
</layout>
</frontend>
</config>
layout file helloworld.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<helloworld_index_index>
<reference name="root">
<action method="setTemplate"><template>page/1column.phtml</template></action>
</reference>
<reference name="content">
<!--<block type="core/template" name="helloworld" template="helloworld/helloworld.phtml"/> -->
<block type="helloworld/helloworld" name="helloworld.helloworld" template="helloworld/helloworld.phtml"/>
</reference>
</helloworld_index_index>
</layout>
Block class file HelloWorld.php
class MyCompanyName_HelloWorld_Block_HelloWorld extends Mage_Core_Block_Template {
}
controlers/ indexController.php
class MyCompanyName_HelloWorld_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
//echo "We're echoing just to show that this is what's called, normally you'd have some kind of redirect going on here";
$this->loadLayout();
$this->renderLayout();
}
}
app/etc/module MyCompanyName_HelloWorld.xml
<?xml version="1.0"?>
<config>
<modules>
<MyCompanyName_HelloWorld>
<active>true</active>
<codePool>local</codePool>
</MyCompanyName_HelloWorld>
</modules>
</config>
Please tell me where i missed the things in it. Thanks in advance..
Upvotes: 0
Views: 11149
Reputation: 7611
Chetan,your block class name is wrong
:
it Should be Helloworld.php instead of HelloWorld.php.
W should be small letter
According magento ,if any class file have two upper letter in file name if should explit into one dir and one file.
example
In MyCompanyName_HelloWorld_Block_HelloWorld the class name after
MyCompanyName_HelloWorld_Block is Hellword,Magenti split class
into Hello is dir Word the class file
Upvotes: 1
Reputation: 2103
Amit Bera is on a right track. However his answer is not fully true. Class and file name can contain upper case letter, but then this letter should be upper case in layout too. The first letter of the class name is an exception - it is always upper case in class name and lower case in layout.
In your case if class name is HelloWorld, so block type in layout should be helloworld/helloWorld like this:
<block type="helloworld/helloWorld" name="helloworld.helloworld" template="helloworld/helloworld.phtml"/>
Upvotes: 3