2017-02-02 3 views
1

Я знаю, что этот вопрос задавался так много раз здесь, но ничего не помогло мне решить мою проблему.Контейнер сетки пользовательского модуля не отображается

Я пытаюсь отобразить сетку на моей индексной странице модулей, но она не отображается, я пытался сделать var_dumpMage::getModel('custombundle/bundle')->getCollection() в цикле и дал мне вывод данных. Ниже то, что я закодированы до сих пор:

config.xml

<?xml version="1.0"?> 
<config> 
    <modules> 
     <Company_CustomBundle> 
      <version>1.0.1</version> 
     </Company_CustomBundle> 
    </modules> 
    <admin> 
     <routers> 
      <custombundle> 
       <use>admin</use> 
       <args> 
        <module>Company_CustomBundle</module> 
        <frontName>admin_custombundle</frontName> 
       </args> 
      </custombundle> 
     </routers> 
    </admin> 

    <global> 
     <helpers> 
      <custombundle> 
       <class>Company_CustomBundle_Helper</class> 
      </custombundle> 
     </helpers> 

     <!-- Blocks --> 
     <blocks> 
      <company_custombundle> 
       <class>Company_CustomBundle_Block</class> 
      </company_custombundle> 
     </blocks> 

     <models> 
      <custombundle> 
       <class>Company_CustomBundle_Model</class> 
       <resourceModel>custombundle_resource</resourceModel> 
      </custombundle> 
      <custombundle_resource> 

       <class>Company_CustomBundle_Model_Resource</class> 

       <entities> 
        <basket> 
         <table>custombundle_basket</table> 
        </basket> 
        <bundle> 
         <table>custombundle_bundle</table> 
        </bundle> 
       </entities> 

      </custombundle_resource> 
     </models> 

     <resources> 

      <custombundle_setup> 
       <setup> 
        <module>Company_CustomBundle</module> 
        <class>Company_CustomBundle_Model_Resource_Setup</class> 
       </setup> 
      </custombundle_setup> 

      <custombundle_write> 
       <connection> 
        <use>core_write</use> 
       </connection> 
      </custombundle_write> 

      <custombundle_read> 
       <connection> 
        <use>core_read</use> 
       </connection> 
      </custombundle_read> 

     </resources> 

    </global> 

    <adminhtml> 

     <!-- Layouts Configuration Starts --> 
     <layout> 
      <updates> 
       <custombundle> 
        <file>custombundle.xml</file> 
       </custombundle> 
      </updates> 
     </layout> 
     <!-- !! Layouts Configuration --> 

     <menu> 
      <custombundle module="custombundle"> 
       <title>Custom Bundle</title> 
       <sort_order>100</sort_order> 
       <children> 
        <index module="custombundle"> 
         <title>Custom Bundle</title> 
         <sort_order>0</sort_order> 
         <action>admin_custombundle/adminhtml_custombundle</action> 
        </index> 

        <other module="custombundle"> 
         <title>Other</title> 
         <sort_order>0</sort_order> 
         <action>admin_custombundle/adminhtml_custombundle/other</action> 
        </other> 
       </children> 
      </custombundle> 
     </menu> 
    </adminhtml> 

</config> 

приложение/дизайн/adminhtml/по умолчанию/по умолчанию/макет/custombundle.xml

<?xml version="1.0"?> 

<layout version="0.1.0"> 

    <adminhtml_custombundle_index> <!-- custombundle controller index action --> 
     <reference name="content"> 
      <block type="company_custombundle/adminhtml_custombundle_bundle" name="list_combination" /> 
     </reference> 
    </adminhtml_custombundle_index> 
</layout> 

контроллеры/Adminhtml/CustombundleController.php

public function indexAction() 
{ 
    $this->_title($this->__('Custom Bundle'))->_title($this->__('Category Combinations'))->loadLayout()->_setActiveMenu('custombundle/index'); 

    $this->renderLayout(); 
} 

Block/Adminhtml/Custombundle/Bundle.php

class Company_CustomBundle_Block_Adminhtml_Custombundle_Bundle extends Mage_Adminhtml_Block_Widget_Grid_Container 
{ 
    public function __construct() 
    { 
     $this->_controller = 'adminhtml_custombundle'; 
     $this->_blockGroup = 'company_custombundle'; 
     $this->_headerText = Mage::helper('company_custombundle')->__('Custom Bundle Category combinations'); 
     $this->_addButtonLabel = Mage::helper('company_custombundle')->__('Add Item'); 
     parent::__construct(); 
    } 
} 

Block/Adminhtml/Custombundle/Bundle/Grid.php

class Company_CustomBundle_Block_Adminhtml_Custombundle_Bundle_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->setId('bundleGrid'); 
     $this->setDefaultSort('bundle_id'); 
     $this->setDefaultDir('DESC'); 
     $this->setSaveParametersInSession(true); 
    } 

    protected function _prepareCollection() 
    { 
     $collection = Mage::getModel('custombundle/bundle')->getCollection(); 
     $this->setCollection($collection); 

     return parent::_prepareCollection(); 
    } 

    protected function _prepareColumns() 
    { 
     $this->addColumn('bundle_id', array(
       'header' => 'ID', 
       'align' => 'right', 
       'width' => '50px', 
       'index' => 'bundle_id', 
     )); 

     $this->addColumn('assigned_category_id', array(
       'header' => 'Assigned with', 
       'align' => 'left', 
       'index' => 'assigned_category_id', 
     )); 

     $this->addColumn('category_id', array(
       'header' => 'Category', 
       'align' => 'left', 
       'index' => 'category_id', 
     )); 

     return parent::_prepareColumns(); 
    } 

    public function getRowUrl($row) 
    { 
     return $this->getUrl('*/*/edit', array('id' => $row->getId())); 
    } 
} 
+0

в «контроллерах/Adminhtml/CustombundleController.php» вы добавили объявление класса? – dharth

+0

да, это есть @dharth Я только что положил 'indexAction' –

+0

ok, в вашем макете попробуйте использовать« custombundle_adminhtml_custombundle_index »вместо« adminhtml_custombundle_index » – dharth

ответ

0

На этот вопрос отвечает правильно на Magento stackexchange по Rajeev и Jaimin вы можете проверить ответ, а также обсуждение here. Эти ребята действительно предоставили ценные материалы и предложили улучшения, улучшающие качество кода.

Я попытаюсь немного объяснить, какие исправления я внес в свой код, который решил мою проблему.

config.xml

<admin> 
    <routers> 
     <adminhtml> 
      <args> 
       <modules> 
        <company_custombundle before="Mage_Adminhtml">Company_CustomBundle_Adminhtml</company_custombundle> 
       </modules> 
      </args> 
     </adminhtml> 
    </routers> 
</admin> 

В config.xml части я изменил router часть, как <use>admin</use> нежелателен 1.9 версии и имели потенциальные угрозы безопасности, как упомянутые Mladen Ilić.

Затем соответствующим образом корректируется меню часть config.xml для поддержки новых маршрутизации, как показано ниже:

<menu> 
    <custombundle module="custombundle"> 
     <title>Custom Bundle</title> 
     <sort_order>100</sort_order> 
     <children> 
      <index module="custombundle"> 
       <title>Custom Bundle</title> 
       <sort_order>0</sort_order> 
       <action>adminhtml/custombundle/index</action> 
      </index> 

      <other module="custombundle"> 
       <title>Other</title> 
       <sort_order>0</sort_order> 
       <action>adminhtml/custombundle/other</action> 
      </other> 
     </children> 
    </custombundle> 
</menu> 

Block/Adminhtml/Custombundle/Bundle.PHP

class Company_CustomBundle_Block_Adminhtml_Custombundle_Bundle extends Mage_Adminhtml_Block_Widget_Grid_Container 
{ 
    public function __construct() 
    { 
     $this->_controller = 'adminhtml_custombundle_bundle'; 
     $this->_blockGroup = 'company_custombundle'; 
     $this->_headerText = Mage::helper('custombundle')->__('Custom Bundle Category combinations'); 
     $this->_addButtonLabel = Mage::helper('custombundle')->__('Add Item'); 
     parent::__construct(); 
    } 
} 

Теперь здесь я изменил adminhtml_custombundle на adminhtml_custombundle_bundle это изменение было сделано потому, что если вы посмотрите на Mage_Adminhtml_Block_Widget_Container::_prepareLayout() метод вы получите, чтобы узнать, что ребенок вашего контейнера т.е. grid или Block/Adminhtml/Custombundle/Bundle/Grid.php никогда не будет вызываться, если вы не делаете это.

Другое изменение в приведенном выше коде было Mage::Helper() Я изменил его значение от company_custombundle до custombundle только без пространства имен.

В конце концов я очистил кэш и перезарядил пурпурный ... * Бинго сетка показывала там данные.

1

Ваш маршрут админ не правильно определен. Вы никогда не должны добавлять новые маршруты администратора, так как это создает проблему безопасности и сильно обескураживается.

<admin> 
    <routers> 
     <adminhtml> 
      <args> 
       <modules> 
        <Company_CustomBundle after="Mage_Adminhtml">Company_CustomBundle_Adminhtml</Company_CustomBundle> 
       </modules> 
      </args> 
     </adminhtml> 
    </routers> 
</admin> 

Более подробно о проблеме администратора маршрута можно найти здесь: https://magento.com/security/patches/supee-6788-technical-details

удачи

+0

Привет @ mladen-ilic спасибо за ваш ценный вклад .. –

+0

@ Сагар Гуэ: Добро пожаловать. Не забудьте отметить правильный ответ. :) –

+0

ответ был отправлен на эту тему http://magento.stackexchange.com/a/157682/38449 вчера, и я добавил тот же ответ с небольшим пояснением здесь. –

Смежные вопросы