Frage

Ich möchte meine eigene Admin-Site erstellen.

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

Auf meiner Admin-Seite wird das HeadText-Byte angezeigt, wodurch ich diese Ausnahme erhalte:

Ausnahme „Mage_Core_Exception“ mit Meldung „ungültiger Blocktyp:Mage_test_block_adminhtml_show_form 'in /var/www/html/magento/app/mage.php:595

Und auf meiner Admin-Seite das:

Fataler Fehler:Rufen Sie zu einer Mitgliederfunktion SetData () unter boolean in /var/www/html/magento/app/code/core/mage/adminhtml/block/widget/form/container.php in Zeile 129

Warum Magento den Block erstellt: Mage_Test_Block_Adminhtml_Show_Form und nicht Mymodule_Test_Block_Adminhtml_Show_Form ???

Der 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();
}}
War es hilfreich?

Lösung

In Ihrer config.xml-Datei in der Datei config.xml hinzufügen in <global>-Tag

generasacodicetagpre.

Andere Tipps

Das sollte so sein:

in Ihrem config.xml

generasacodicetagpre.

und in Ihrem Controller

generasacodicetagpre.

Auf Ihrem config.xml Datei, in der Sie keine Klasse definieren

Aber Sie müssen die Blockklasse unter aufrufen Mymodule_Test_Block_Adminhtml_Show bei ShowController.php

Gemäß dem Magento-System, Sie kann keine direkte Klasse verwenden Namen auf createBlock Funktion.

Die Blockklasse muss nach Blocktyp aufgerufen werden

Daher muss der Blocktyp in XML definiert werden

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

        <helpers>
    ...

Wie Sie die Klasse nennen möchten Mymodule_Test_Block_Adminhtml_Show Dann

Der Blocktyp sollte sein 'test/adminhtml_show'

Gemäß Magento-System

  • test => Mymodule_Test_Block
  • adminhtml_show =>Adminhtml_Show

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

ändern

$this->getLayout()->createBlock('test/adminhtml_show')
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit magento.stackexchange
scroll top