0

I have added a custom module to magento admin panel, my Controller is as following

    <?php
class ABC_Adminhello_AdminhelloController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();

        $block = $this->getLayout()->createBlock('adminhello\adminhtml_export');

        $this->getLayout()->getBlock('content')->append($block);
        $this->_setActiveMenu('sales/order')
                ->renderLayout();
    }
}

and My block is like this

    <?php
class ABC_Adminhello_Block_Adminhtml_Export extends Mage_Adminhtml_Block_Widget_Form_Container
{
  public function __construct()
  {
    $this->setTemplate('export/order.phtml');  
  }


}

The problem is that in my Controller

$this->getLayout()->createBlock('adminhello\adminhtml_export');

returns false, no block is crated, I am unable to find the reason.

  • $this->renderLayout(); remove that – Qaisar Satti Jan 12 '16 at 12:33
  • Try Mage::app()->getLayout()->createBlock('adminhello\adminhtml_export'); – Rohit Kundale Jan 12 '16 at 12:35
  • Nothing working, still getLayout()->createBlock('adminhello\adminhtml_export'); returns false – Abdul Ghaffar Jan 12 '16 at 12:50
  • Is there any other way to load view for module? – Abdul Ghaffar Jan 12 '16 at 12:52
2

Replace your indexAction() function with the below:

  public function indexAction() {

    $this->loadLayout();

    $this->_setActiveMenu('sales/order')

    $this->_addContent($this->getLayout()->createBlock('adminhello/adminhtml_export'))

    $this->renderLayout();

   }

If this does not work, share your config.xml so that I can help you further with this.

2
$this->getLayout()->createBlock('adminhello\adminhtml_export');

returns false, no block is crated, I am unable to find the reason.

That's because you wrote the class alias with a backslash \ instead of a forward slash /.

Besides that you should remove the first call to renderLayout() and only call it once at the end:

0

Follow bellow steps

Step : 1 Create adminhello.xml at location app\design\adminhtml\default\default\layout\

<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhello_adminhtml_adminhello_index>
        <reference name="content">
            <block type="adminhello/adminhtml_export" name="export" />
        </reference>
    </adminhello_adminhtml_adminhello_index>
</layout>

Step :2 Create controller file AdminhelloController.php at location app\code\local\ABC\Adminhello\controllers\Adminhtml\AdminhelloController

<?php
class ABC_Adminhello_Adminhtml_AdminhelloController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction() 
    {
        $this->loadLayout()
             ->_setActiveMenu('sales/order')
             ->renderLayout();
    }
}
  • Both solutions are not working – Abdul Ghaffar Jan 12 '16 at 12:48
  • Is there any other way to load view for module? – Abdul Ghaffar Jan 12 '16 at 12:52
  • have you created layout file adminhello.xml at location app\design\adminhtml\default\default\layout\ – Abdul Jan 12 '16 at 13:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.