문제

내 자신의 관리 사이트를 만들고 싶습니다.

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>
.

컨트롤러 \ 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();
}}
.

블록 \ 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이 예외를 얻는 HeadText Byt OW :

예외 'Mage_core_Exception'메시지가 잘못된 블록 유형 : Mage_Test_BLOCK_ADMINHTML_SHOW_FORM 'AN. /var/www/html/magento/app/mage.php:595

및 내 관리 페이지에서 다음과 같습니다.

치명적인 오류 : 부울에 멤버 함수 setData () 호출 /var/www/html/magento/app/code/core/mage/adminhtml/block/widget/form/container.php. 129 번 줄

왜 magento는 mage_test_block_adminhtml_show_form 이 아니라 mymodule_test_block_adminhtml_show_form ???

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();
}}
.

도움이 되었습니까?

해결책

<global> 태그에 config.xml 파일에 다음을 추가하십시오

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

다른 팁

이와 같아야합니다.

config.xml

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

및 컨트롤러에서

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

config.xml 파일에서 클래스를 정의하지 않음

그러나 Mymodule_Test_Block_Adminhtml_Show

에서 ShowController.php에서 블록 클래스를 호출합니다.

Magento 시스템의 경우 createblok 함수에서 직접 클래스 이름을 사용할 수 없습니다.

블록 유형으로 블록 클래스를 호출 할 필요가

이렇게 XML 에서 블록 유형을 정의해야합니다

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

        <helpers>
    ...
.

Class Mymodule_Test_Block_Adminhtml_Show 클래스를 호출 할 때

IT 블록 유형은 'test/adminhtml_show'

이어야합니다.

자홍색 시스템

  • test => Mymodule_Test_Block
  • adminhtml_show =>Adminhtml_Show

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

로 변경
$this->getLayout()->createBlock('test/adminhtml_show')
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top