2

I know this question has been asked for so many times here on SO but nothing helped me to solve my issue.

enter image description here

I am trying to display a grid on my modules index page but it is not showing, I tried to var_dump Mage::getModel('custombundle/bundle')->getCollection() in a loop and it gave me output of data. Below is what I have coded so far:

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Company_CustomBundle>
            <version>1.0.1</version>
        </Company_CustomBundle>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <company_custombundle before="Mage_Adminhtml">Company_CustomBundle_Adminhtml</company_custombundle>
                    </modules>
                </args>
            </adminhtml>
        </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>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>
    </adminhtml>

</config>

app/design/adminhtml/default/default/layout/custombundle.xml

<?xml version="1.0"?>

<layout version="0.1.0">

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

controllers/Adminhtml/CustombundleController.php

public function indexAction()
{
    $this->loadLayout();
    $this->_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_bundle';
        $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()));
    }
}
2
  • Can you update the question with new code? Also check for errors in log files if any. Feb 2, 2017 at 13:29
  • errors anot getting generated, updated the question
    – Sagar Guhe
    Feb 2, 2017 at 13:36

2 Answers 2

2

In a quick look, I think there is something wrong with the protected property value $_controller of your grid container. So try to use this.

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('company_custombundle')->__('Custom Bundle Category combinations');
        $this->_addButtonLabel = Mage::helper('company_custombundle')->__('Add Item');
        parent::__construct();
    }
}

The only change here is, adminhtml_custombundle is changed to adminhtml_custombundle_bundle. This value is used to effectively identify grid class. As per definition of your classes, that tail part (ie _bundle) is also essential to correctly point towards your grid class. (ie Company_CustomBundle_Block_Adminhtml_Custombundle_Bundle_Grid)

EDIT - 1

I think your router definition is also wrong . you need to correct that in your config.xml file like this

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

The definition that you are using is deprecated from Magento 1.9 version. It is also not recommended to use.

There is also changes needed in the menu definition section as per above router change.

Try to use this:

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

Changes here are inside action node.

Edit - 2

Please keep the grid container change also in your code. It is essential. If it is not working, then try to simplify your indexAction() method in your controller like this.

public function indexAction()
{
    $this->loadLayout();
    $this->_setActiveMenu('custombundle/index');
    $this->renderLayout();
}

After this changes are made, do not forget to clear your cache before test it.

14
  • Hi @rajeev-k-tomy I was expecting your answer :D , sorry but this didn't work for me...
    – Sagar Guhe
    Feb 2, 2017 at 13:00
  • can you see anything while you click on your custom menu ? Feb 2, 2017 at 13:02
  • I am taken to the controllers action view but the block is not getting rendered there... let me update question with screenshot..
    – Sagar Guhe
    Feb 2, 2017 at 13:10
  • please see my edit. there are some more mistakes I can see now. Keep first change too. Feb 2, 2017 at 13:12
  • 1
    Okay. can you change action value to adminhtml/custombundle and try again. If that is not working, please try adminhtml/custombundle/index too. Let me know whether that works for you. Feb 2, 2017 at 13:22
3

Try below updates, First, using <use>admin</admin> is not a good approach anymore. You need to use it as below, Replace in your config.xml

<admin>
    <routers>
        <custombundle>
            <use>admin</use>
            <args>
                <module>Company_CustomBundle</module>
                <frontName>admin_custombundle</frontName>
            </args>
        </custombundle>
    </routers>
</admin>

With

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

Now update your app/design/adminhtml/default/default/layout/custombundle.xml with below code.

<?xml version="1.0"?>
<layout version="0.1.0">
    <adminhtml_custombundle_index>
        <reference name="content">
            <block type="custombundle/adminhtml_custombundle_bundle" name="list_combination" />
        </reference>
    </adminhtml_custombundle_index>
</layout>
2
  • Now page not found error is coming..
    – Sagar Guhe
    Feb 2, 2017 at 13:08
  • I have updated the question with suggested improvments
    – Sagar Guhe
    Feb 2, 2017 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.