I have successfully added an admin controller which extends Mage_Adminhtml_Controller_Action and works, now I am trying to use a block and template.
I expect to see the text "text here", but I don't see any text, I see the Magento admin header/footer with a blank area, at this URL: http://127.0.0.1/magento2/index.php/admin/c2/index/key/f5b1fd39ee6e77040cb4c6fbe7340ffd/ (Obviously, the link is a localhost link, but I've shown it for verification!)
My namespace is NS1
My module is Component Management
Here's my files.
app/code/local/NS1/ComponentManagement/controllers/c2Controller.php
<?php
class NS1_ComponentManagement_c2Controller extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
$this->renderLayout();
}
}
--
app/code/local/NS1/ComponentManagement/Block/Adminhtml/MyBlock.php
<?php
class NS1_ComponentManagement_Block_Adminhtml_ComponentManagement extends Mage_Adminhtml_Block_Template
{
public function methodblock()
{
return 'text here';
}
}
--
app/design/adminhtml/NS1/ComponentManagement/template/company.php
<?php
echo $this->methodblock();
--
app/design/adminhtml/NS1/ComponentManagement/layout/adminhtml.xml
<?xml version="1.0"?>
<layout version="0.1.0">
<mymodulename_adminhtml_mymodulename_index>
<reference name="content">
<block type="NS1_ComponentManagement/adminhtml_componentmanagement" name="NS1.ComponentManagement" template="company.phtml" />
</reference>
</mymodulename_adminhtml_mymodulename_index>
</layout>
--
app/code/local/NS1/ComponentManagement/etc/config.xml
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<NS1_ComponentManagement>
<version>0.0.1</version>
</NS1_ComponentManagement>
</modules>
<frontend>
<routers>
<routeurfrontend>
<use>standard</use>
<args>
<module>NS1_ComponentManagement</module>
<frontName>test</frontName>
</args>
</routeurfrontend>
</routers>
<layout>
<updates>
<ComponentManagement>
<file>test.xml</file>
</ComponentManagement>
</updates>
</layout>
</frontend>
<global>
<blocks>
<ComponentManagement>
<class>NS1_ComponentManagement_Block</class>
</ComponentManagement>
</blocks>
<helpers>
<ComponentManagement>
<class>NS1_ComponentManagement_Helper</class>
</ComponentManagement>
</helpers>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<NS1_ComponentManagement after="Mage_Adminhtml">NS1_ComponentManagement</NS1_ComponentManagement>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
--
1 Answer 1
I think you have two issues here.
Your layout handle seems wrong
I think your handle should be something like adminhtml_componentmanagement_index
But what you can do is add some debug into your controller to find the right handle. The following snippet added to your controller action var_dump all the layout handles on the page so you can validate the correct one.
`$this->getLayout()->getUpdate()->getHandles()`
Need to add the admin layout xml
In your module's config.xml I think you are missing the snippet to add the layout xml files.
<adminhtml>
<layout>
<updates>
<your_module>
<file>path/to/layout.xml</file>
</your_module>
</updates>
</layout>
</adminhtml>