1

I want to create my own admin site.

config.xml :

<config>
    <modules>
        <Mymodule_Test>
            <version>0.1.0</version>
        </Mymodule_Test>
    </modules>
    <global>
        <helpers>
            <test>
                <class>Mymodule_Test_Helper</class>
            </test>
        </helpers>
    </global>
    <admin>
        <routers>
            <mymoduletest>
                <use>admin</use>
                <args>
                   <module>Mymodule_Test</module>
                   <frontName>mymoduletest</frontName>
                </args>
            </mymoduletest>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <test>
                    <file>test.xml</file>
                </test>
            </updates>
        </layout>
    </adminhtml>
</config>

adminhtml.xml:

<menu>
    <test translate="title" module="test">
        <title>Test</title>
        <sort_order>300</sort_order>
        <children>
            <!-- child items go here -->
            <show translate="title" module="test">
                <title>SubTest</title>
                <sort_order>10</sort_order>
                <action>mymoduletest/adminhtml_show</action>
            </show>
        </children>
    </test>
</menu>

controllers\Adminhtml\ShowController.php :

<?php Class Mymodule_Test_Adminhtml_ShowController extends Mage_Adminhtml_Controller_Action{

protected function _initAction()
{
    $this->loadLayout();
    $this->_setActiveMenu('test/show');
    return $this;
}

public function indexAction()
{
    $this->_initAction()
         ->_addContent($this->getLayout()->createBlock('Mymodule_Test_Block_Adminhtml_Show'))
         ->renderLayout();
}}

Block\Adminhtml\Show.php :

<?php class Mymodule_Test_Block_Adminhtml_Show extends Mage_Adminhtml_Block_Widget_Form_Container{

public function __construct()
{

    parent::__construct();

    $this->removeButton('back');
    $this->removeButton('reset');
    $this->removeButton('delete');
    $this->removeButton('add');
    $this->removeButton('save');
    $this->removeButton('edit');

    $this->setId('testContainer');

    $this->_blockGroup = 'test';
    $this->_controller = 'adminhtml';
    $this->_mode = 'show';

    $this->_headerText  = 'TEST';
}}

My admin page shows the headText byt ow I get this exception:

exception 'Mage_Core_Exception' with message 'invalid block type: Mage_Test_Block_Adminhtml_Show_Form' in /var/www/html/magento/app/Mage.php:595

And on my admin page this:

Fatal error: Call to a member function setData() on boolean in /var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php on line 129

Why magento creates the block: Mage_Test_Block_Adminhtml_Show_Form and not Mymodule_Test_Block_Adminhtml_Show_Form ???

The Block\Adminhtml\Show\Form.php :

<?php class Mymodule_Test_Block_Adminhtml_Show_Form extends Mage_Adminhtml_Block_Widget_Form {

public function __construct()
{
    parent::__construct();

    $this->setId('showGeneralForm');
    $this->setTemplate('test/show.phtml');
}

protected function _beforeToHtml()
{
    return parent::_beforeToHtml();
}}
  • please include all of your etc/config.xml file. – Adarsh Khatri Jun 19 '15 at 11:57
  • Edit: add full config.xml – user27294 Jun 19 '15 at 12:07
1

add following in your config.xml file in <global> tag

<blocks>
    <test>
      <class>Mymodule_Test_Block</class>
   </test>
</blocks>
1

This should be like this:

in your config.xml

<config>
.....
    <global>
       .......
       <blocks>
            <test>
               <class>Mymodule_Test_Block</class>
            </test>
       </blocks>
      .......
    </global>
.....
</config>

and in your controller

public function indexAction()
{
    $this->_initAction()
         ->_addContent($this->getLayout()->createBlock('test/adminhtml_show'))
         ->renderLayout();
}
1

On your config.xml file your do not define class

But you have call the block class on at Mymodule_Test_Block_Adminhtml_Show at ShowController.php

As per as magento system,you cannot use direct class name on createBlok function.

Need call the block class by block type

So, need to define block type at xml

<global>
        <blocks>
            <test> <-- module block identifire -->
                <class>Mymodule_Test_Block</class>
            </test>
        </blocks>

        <helpers>
    ...

As you want to call class Mymodule_Test_Block_Adminhtml_Show then

it block type should be 'test/adminhtml_show'

As per as magento system

  • test => Mymodule_Test_Block
  • adminhtml_show =>Adminhtml_Show

$this->getLayout()->createBlock('Mymodule_Test_Block_Adminhtml_Show')

change to

$this->getLayout()->createBlock('test/adminhtml_show')

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.