Magento Adminhtml createblock() نموذج "Mage_Core_Exception" نوع الكتلة غير صالح

magento.stackexchange https://magento.stackexchange.com//questions/71574

سؤال

أريد إنشاء موقع الإدارة الخاص بي.

التكوين.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';
}}

تعرض صفحة الإدارة الخاصة بي بايت نص الرأس حتى أحصل على هذا الاستثناء:

الاستثناء "Mage_Core_Exception" مع الرسالة "نوع الكتلة غير صالح:mage_test_block_adminhtml_show_form 'in /var/www/html/magento/app/mage.php:595

وعلى صفحة المشرف الخاصة بي هذا:

خطأ فادح:اتصل على وظيفة عضو setData () على boolean in /var/www/html/magento/app/code/core/mage/adminhtml/block/widget/form/container.php على الخط 129

لماذا يقوم الماجنتو بإنشاء الكتلة: 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

giveacodicetagpre.

وفي وحدة تحكم

giveacodicetagpre.

على config.xml الملف الخاص بك لا تحدد فئة

ولكن يجب استدعاء كتلة الدرجة في Mymodule_Test_Block_Adminhtml_Show في ShowController.php

كما في مثل الماجنتو ، لا يمكن استخدام المباشر الدرجة اسم على createBlok وظيفة.

تحتاج إلى استدعاء كتلة فئة من نوع كتلة

لذا تحتاج إلى تحديد نوع كتلة في xml

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

        <helpers>
    ...

كما كنت ترغب في الاتصال الدرجة Mymodule_Test_Block_Adminhtml_Show ثم

فإنه كتلة يجب أن يكون نوع '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