質問

私は自分の管理サイトを作成したい。

コンフィグ...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\ショー。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';
}}

私の管理ページには、この例外が発生するheadText byt oが表示されます:

メッセージ'無効なブロックタイプ'を含む例外'Mage_Core_Exception':Mage_test_block_adminhtml_show_form'in /var/www/html/magento/app/Mage.価格: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 ???

ブロック\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();
}}
役に立ちましたか?

解決

config.xmlファイルに次の追加を追加します.<global>タグ

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

Magentoシステムごとに、あなたは 直接クラスを使用できません ネームオン クリエートブロック 機能。

ブロックタイプ別にブロッククラスを呼び出す必要があります

したがって、xmlでブロック型を定義する必要があります

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

        <helpers>
    ...

クラスを呼び出したいように Mymodule_Test_Block_Adminhtml_Show その後、

ブロックタイプは次のようになります 'test/adminhtml_show'

Magentoシステムごとに

  • 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