Pergunta

Eu quero criar o meu próprio site de administração.

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';
}}

A minha página de administração mostra o headText byt uxo eu recebo essa exceção:

exceção 'Mage_Core_Exception" com a mensagem " tipo de bloco inválido:Mage_Test_Block_Adminhtml_Show_Form' em /var/www/html/magento/app/Mago.php:595

E na minha página de administração este:

Erro Fatal:Chamada para uma função de membro setData() no booleano em /var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Widget/Form/Container.php na linha 129

Por que magento cria o bloco: Mage_Test_Block_Adminhtml_Show_Form e não Mymodule_Test_Block_Adminhtml_Show_form ???

O 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();
}}
Foi útil?

Solução

adicionar o seguinte em seu config.xml em ficheiro <global> marca

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

Outras dicas

Isso deve ser como este:

em seu config.xml

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

e no seu controlador,

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

No seu config.xml o seu arquivo não definem classe

Mas você tem de chamar o bloco classe a Mymodule_Test_Block_Adminhtml_Show no ShowController.php

Conforme magento sistema,você não é possível usar o direct classe nome createBlok função.

Precisa chamar o bloco de classe por tipo de bloco

Assim, necessário definir o tipo de bloco em xml

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

        <helpers>
    ...

Como você quiser chamar de classe Mymodule_Test_Block_Adminhtml_Show em seguida,

é o tipo de bloco deve ser 'test/adminhtml_show'

Conforme magento sistema

  • test => Mymodule_Test_Block
  • adminhtml_show =>Adminhtml_Show

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

mudança para

$this->getLayout()->createBlock('test/adminhtml_show')
Licenciado em: CC-BY-SA com atribuição
Não afiliado a magento.stackexchange
scroll top