簡體   English   中英

無效的塊類型-自定義網格-Magento管理面板

[英]Invalid block type - Custom Grid - Magento Admin Panel

我制作了一個模塊並且已經注冊了..它的工作完全正常,直到我想創建一個自定義網格...我在下面的代碼中寫了必要的文件,但拋出了一個異常,我指定了無效的塊類型。 我已經經歷了很多次,但我無法弄清錯誤。

/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/Block/Adminhtml/Questionanswer

  <?php

    class Maven_Questionanswer_Block_Adminhtml_Questionanswer_Question extends Mage_Adminhtml_Block_Widget_Grid_Container
    {
        public function __construct()
        {
            $this->_blockGroup = 'questionanswer';
            $this->_controller = 'adminhtml_question';
            $this->_headerText =  Mage::helper('questionanswer')->__('questionanswer');
            $this->_addButtonLabel = 'Add Question';
            parent::__construct();
        }
    }
?>

/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/Block/Adminhtml/Questionanswer/Questionanswer

  <?php

    class Maven_Questionanswer_Block_Adminhtml_Questionanswer_Questionanswer_Grid extends Mage_Adminhtml_Block_Widget_Grid
    {
        public function __construct()
       {
           parent::__construct();
           $this->setId('questionGrid');
           $this->setDefaultSort('question_id');
           $this->setDefaultDir('DESC');
           $this->setSaveParametersInSession(true);
       }
        protected function _prepareCollection()
        {
            $collection = Mage::getModel('questionanswer/question')->getCollection();
            $this->setCollection($collection);
            parent::_prepareCollection();
            return $this;
        }

        protected function _prepareColumns()
        {
            $helper = Mage::helper('questionanswer');

            $this->addColumn('question_id',
                 array(
                        'header' => 'ID',
                        'align' =>'right',
                        'width' => '50px',
                        'index' => 'id_pfay_test',
                   ));
           $this->addColumn('username',
                   array(
                        'header' => 'Username',
                        'align' =>'left',
                        'index' => 'username',
                  ));
           $this->addColumn('email', array(
                        'header' => 'email',
                        'align' =>'left',
                        'index' => 'email',
                 ));
            $this->addColumn('question', array(
                         'header' => 'question',
                         'align' =>'left',
                         'index' => 'question',
              ));
            $this->addColumn('status', array(
                         'header' => 'status',
                         'align' =>'left',
                         'index' => 'status',
              ));
             return parent::_prepareColumns();
         }

        public function getGridUrl()
        {
            return $this->getUrl('*/*/grid', array('_current'=>true));
        }
    }

**/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/controllers/Adminhtml**

    <?php

    class Maven_Questionanswer_Adminhtml_QuestionController extends Mage_Adminhtml_Controller_Action
    {


        public function indexAction()
        {
            $this->_title($this->__('Question'))->_title($this->__('Question Answer'));
            $this->loadLayout();
            $this->_setActiveMenu('questionanswer/question');
            $this->_addContent($this->getLayout()->createBlock('maven_questionanswer/adminhtml_questionanswer_question'));
            $this->renderLayout();
        }

        public function gridAction()
        {
            $this->loadLayout();
            $this->getResponse()->setBody(
            $this->getLayout()->createBlock('maven_questionanswer/adminhtml_questionanswer_questionanswer_grid')->toHtml());

        }

        // public function exportInchooCsvAction()
        // {
        //     $fileName = 'orders_inchoo.csv';
        //     $grid = $this->getLayout()->createBlock('inchoo_orders/adminhtml_sales_order_grid');
        //     $this->_prepareDownloadResponse($fileName, $grid->getCsvFile());
        // }

        // public function exportInchooExcelAction()
        // {
        //     $fileName = 'orders_inchoo.xml';
        //     $grid = $this->getLayout()->createBlock('inchoo_orders/adminhtml_sales_order_grid');
        //     $this->_prepareDownloadResponse($fileName, $grid->getExcelFile($fileName));
        // }


    }
?>

/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/etc/config.xml

  <blocks>
                <questionanswer>
                    <class>Maven_Questionanswer_Block</class>
                </questionanswer>
            </blocks>

    <admin>
            <routers>
                <adminhtml>
                    <use>admin</use>
                    <args>
                        <modules>
                            <maven_questionanswer>Maven_Questionanswer_Adminhtml</maven_questionanswer>
                        </modules>
                    </args>
                </adminhtml>
            </routers>
        </admin>

and in adminhtml.xml

<?xml version="1.0" encoding="UTF-8"?>
    <adminhtml>
        <menu>
            <questionanswer translate="title" module="questionanswer">
                <title>Question Answer</title>
                <sort_order>60</sort_order>
                <children>
                     <questionanswer_question module="questionanswer">
                        <title>Question</title> 
                        <action>adminhtml/question</action>
                     </questionanswer_question> 
                </children>      
            </questionanswer> 
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <system>
                            <children>
                                <config>
                                    <children>
                                        <questionanswer_section>
                                            <title>Question-Answer</title>
                                        </questionanswer_section>
                                    </children>
                                </config>
                            </children>
                        </system>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>

我還創建了一個空白助手...我在哪里出錯?

根據Grid塊,您的目錄結構似乎Grid 請按照以下步驟解決您的問題:

第1步:從以下位置重新定位Grid.php文件:

/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/Block/Adminhtml/Questionanswer/Questionanswer

/home/vhost/_default/magento1.9.2/app/code/local/Maven/Questionanswer/Block/Adminhtml/Questionanswer/

第2步:更改網格類名稱:

Maven_Questionanswer_Block_Adminhtml_Questionanswer_Questionanswer_Grid

Maven_Questionanswer_Block_Adminhtml_Questionanswer_Grid

步驟3:清除Magento緩存並嘗試運行加載網格頁面。


更新:

請更換:

$這 - > getLayout() - > createBlock( 'maven_questionanswer / adminhtml_questionanswer_questionanswer_grid') - > toHtml());

$這 - > getLayout() - > createBlock( '問題答案/ adminhtml_questionanswer_questionanswer_grid') - > toHtml());

當你宣布你的塊為questionanswer而不是maven_questionanswer

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM