I'm trying to create custom admin module in Magento CE 1.9.2.4.
The module has two blocks because I thought it would be nice to move the logic parts of these views into their block files.
So the problem is I can't call methods in the block files from the templates. If I don't try to do the call the template files' HTML content is displayed normally, but if I try to do the call (as shown below) the template where the call resides doesn't show up. Probably has something to do with the exception I keep having.
Invalid block type: Company_Modulename_Block_Adminhtml_Productlist
What am I doing wrong? What should the block type be?
var/log/exception.log
2016-10-20T08:26:57+00:00 ERR (3):
exception 'Mage_Core_Exception' with message 'Invalid block type: Mage_Company_Modulename_Block_Adminhtml_Productlist' in /Users/username/Sites/magento/app/Mage.php:595
Stack trace:
#0 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(495): Mage::throwException('Invalid block t...')
#1 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(437): Mage_Core_Model_Layout->_getBlockInstance('company_modulena...', Array)
#2 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(472): Mage_Core_Model_Layout->createBlock('company_modulena...', 'oa_productlist')
#3 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(239): Mage_Core_Model_Layout->addBlock('company_modulena...', 'oa_productlist')
#4 /Users/username/Sites/magento/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 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(206): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#6 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/Layout.php(210): Mage_Core_Model_Layout->generateBlocks(Object(Mage_Core_Model_Layout_Element))
#7 /Users/username/Sites/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(344): Mage_Core_Model_Layout->generateBlocks()
#8 /Users/username/Sites/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(269): Mage_Core_Controller_Varien_Action->generateLayoutBlocks()
#9 /Users/username/Sites/magento/app/code/core/Mage/Adminhtml/Controller/Action.php(275): Mage_Core_Controller_Varien_Action->loadLayout(NULL, true, true)
#10 /Users/username/Sites/magento/app/code/local/Company/ModuleName/controllers/Adminhtml/ModulenamebackendController.php(23): Mage_Adminhtml_Controller_Action->loadLayout()
#11 /Users/username/Sites/magento/app/code/local/Company/ModuleName/controllers/Adminhtml/ModulenamebackendController.php(10): Company_ModuleName_Adminhtml_ModulenamebackendController->showContent()
#12 /Users/username/Sites/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Company_ModuleName_Adminhtml_ModulenamebackendController->indexAction()
#13 /Users/username/Sites/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
#14 /Users/username/Sites/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#15 /Users/username/Sites/magento/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#16 /Users/username/Sites/magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#17 /Users/username/Sites/magento/index.php(83): Mage::run('', 'store')
#18 {main}
And here are the files that have something to do with the module (I hope I didn't forget anything):
app/etc/modules/Company_Modulename.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Modulename>
<active>true</active>
<codePool>local</codePool>
<version>0.1.0</version>
</Company_Modulename>
</modules>
</config>
app/code/local/Company/Modulename/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Company_Modulename>
<version>0.1.0</version>
</Company_Modulename>
</modules>
<global>
<blocks>
<company_modulename>
<class>Company_Modulename_Block</class>
</company_modulename>
</blocks>
</global>
<admin>
<routers>
<modulename>
<use>admin</use>
<args>
<module>Company_Modulename</module>
<frontName>company_modulename</frontName>
</args>
</modulename>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<modulename>
<file>modulename.xml</file>
</modulename>
</updates>
</layout>
</adminhtml>
</config>
app/code/local/Company/Modulename/controllers/Adminhtml/ModulenamebackendController.php
class Company_Modulename_Adminhtml_ModulenamebackendController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->_title($this->__("Custom title"));
$this->renderLayout();
}
}
app/code/local/Company/Modulename/Block/Adminhtml/Modulenamebackend.php
class Company_Modulename_Block_Adminhtml_Modulenamebackend extends Mage_Adminhtml_Block_Template{}
app/code/local/Company/Modulename/Block/Adminhtml/Productlist.php
class Company_Modulename_Block_Adminhtml_Productlist extends Mage_Adminhtml_Block_Template
{
public function myfunction()
{
return "Hello world";
}
}
app/code/local/Company/Modulename/Block/Adminhtml/Optionlist.php
class Company_Modulename_Block_Adminhtml_Optionlist extends Mage_Adminhtml_Block_Template{}
app/design/adminhtml/default/default/layout/modulename.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<modulename_adminhtml_modulenamebackend_index>
<reference name="content">
<block type="core/template" name="modulename" template="modulename/view.phtml">
<block type="company_modulename/adminhtml_productlist" as="mn_productlist" name="mn_productlist" template="modulename/productlist.phtml" />
<block type="company_modulename/adminhtml_optionlist" as="mn_optionlist" name="mn_optionlist" template="modulename/optionlist.phtml" />
</block>
</reference>
</modulename_adminhtml_modulenamebackend_index>
</layout>
app/design/adminhtml/default/default/template/modulename/view.phtml
<h2>Something</h2>
<div>
<?php echo $this->getChildHtml('mn_productlist') ?>
</div>
<div>
<?php echo $this->getChildHtml('mn_optionlist') ?>
</div>
app/design/adminhtml/default/default/template/modulename/optionlist.phtml
<p>This is some content</p>
app/design/adminhtml/default/default/template/modulename/productlist.phtml
<p>This text shows if the php on this file is commented</p>
<?php
echo $this->myfunction();
?>