0

I am new to magento. I am creating custom module and trying to display custom grid in admin area of custom module but I am not able to display grid. I found related questions but still not getting expected output. Not able to figure out where exactly problem. Please help me out.

_prepareCollection() returns boolean false.

please check my code below:

<?php

class Bespoke_Suites_Block_Adminhtml_Suites_Grid extends Mage_Adminhtml_Block_Widget_Grid{

public function _construct(){
    parent::_construct();
    $this->setId('suitesGrid');
    $this->setUseAjax(true);
    $this->setDefaultSort('suites_id');
    $this->setDefaultDir('DESC');
    $this->setSaveParametersInSession(true);
}

public function _prepareCollection(){
    $collection = Mage::getModel('bespoke_suites/suites')->getCollection();
    var_dump($collection);//returns boolean false
    $this->setCollection($collection);
    return parent::_prepareCollection();

}

protected function _prepareColumns() {
    $this->addColumn('material', array(
           'type' => 'text',
           'index' => 'material',
           'header' => Mage::helper('suites')->__('Material')
    ));

    $this->addColumn('color', array(
           'type'=>'text',
           'index'=>'color',
           'header'=>$this->__('Color')
    ));

    $this->addColumn('measurements', array(
           'type'=> 'text',
           'index'=>'measurements',
           'header'=>$this->__('Measurements')
    ));

    $this->addColumn('thread', array(
            'type'=>'text',
            'index'=>'thread',
            'header'=>$this->__('Thread')
    ));

    $this->addColumn('buttons', array(
            'type'=>'text',
            'index'=>'buttons',
            'header'=>$this->__('Buttons')
    ));

    $this->addColumn('collar', array(
            'type'=> 'text',
            'index'=>'collar',
            'header'=>$this->__('Collar Style')
    ));

    $this->addColumn('handcuff', array(
            'type'=>'text',
            'index'=>'handcuff',
            'header'=>$this->__('Handcuff Style')
    ));

    $this->addColumn('pocket', array(
            'type'=>'text',
            'index'=>'pocket',
            'header'=>$this->__('Pocket Style')
    ));

    $this->addColumn('back', array(
            'type'=> 'text',
            'index'=>'back',
            'header'=>$this->__('Back Style')
    ));
    return $this;
}

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

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

And my gridAction() is

public function gridAction()
{
    $this->loadLayout();
    /**
     * Display sample text in admin area
     *  */

    $this->_addContent(
            $this->getLayout()->createBlock('core/text')->setText('Some Text')
    );

    $this->getLayout()->getBlock('head')->setTitle($this->__('Name Module'));
    $this->_headerText = Mage::helper('Suites')->__('Name - Module');
    $this->getResponse()->setBody(
        $this->getLayout()->createBlock('bespoke_suites/adminhtml_suites_grid')->toHtml()
    );

    $this->_setActiveMenu('suites');
    $this->renderLayout();
}

config.xml

<?xml version="1.0"?>
<config>
 <modules>
    <Bespoke_Suites>
        <version>1.0.0.0.1</version>
    </Bespoke_Suites>
</modules>
<global>
    <models>
        <bespoke_suites>
            <class>Bespoke_Suites_Model</class>
            <resourceModel>suites_resource</resourceModel>
        </bespoke_suites>
        <!-- <suites_resource>
            <class>Bespoke_Suites_Model_Resource</class>
            <entities>
                <suites>
                    <table>bespoke_suites</table>
                </suites>
            </entities>
        </suites_resource>
        -->
        <bespoke_suites_resource>
            <class>Bespoke_Suites_Resource</class>
            <entities>
                <suites>
                    <table>bespoke_suites</table>
                </suites>
            </entities>
        </bespoke_suites_resource>
    </models>
    <helpers>
        <bespoke_suites>
            <class>Bespoke_Suites_Helper</class>
        </bespoke_suites>
    </helpers>
    <blocks>
        <bespoke_suites>
            <class>Bespoke_Suites_Block</class>
        </bespoke_suites>
        <suites>
            <class>Bespoke_Suites_Block</class>
        </suites>
    </blocks>
    <blocks>
        <adminhtml>
            <rewrite>
                <bespoke_suites_grid>Bespoke_Suites_Block_Adminhtml_Bespoke_Suites_Grid</bespoke_suites_grid>
            </rewrite>
        </adminhtml>
    </blocks>
    <resource>
        <bespoke_suites_setup>
            <setup>
                <module>Bespoke_Suites</module>
                <class>Bespoke_Suites_Model_Resource_Setup</class>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </bespoke_suites_setup>
        <bespoke_suites_write>
            <connection>
                <use>core_write</use>
            </connection>
        </bespoke_suites_write>
        <bespoke_suites_read>
            <connection>
                <use>core_read</use>
            </connection>
        </bespoke_suites_read>
    </resource>
</global>
<frontend>
    <routers>
        <!-- <bespoke_suites>
            <use>standard</use>
            <args>
                <module>Bespoke_Suites</module>
                <frontName>suites</frontName>
            </args>
        </bespoke_suites> -->
        <suites>
            <use>standard</use>
            <args>
                <module>Bespoke_Suites</module>
                <frontName>suites</frontName>
            </args>
        </suites>
    </routers>
    <layout>
        <updates>
            <suites>
                <file>suites.xml</file>
            </suites>
        </updates>
    </layout>
    <!-- <layout>
        <updates>
            <bespoke_suites>
                <file>bespoke_suites.xml</file>
            </bespoke_suites>
        </updates>
    </layout> -->
</frontend>
<admin>
    <routers>
        <adminhtml>
            <use>admin</use>
            <args>
                <modules>
                    <Bespoke_Suites before="Mage_Adminhtml">Bespoke_Suites_adminhtml</Bespoke_Suites>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
<adminhtml>
    <layout>
        <updates>
            <bespoke_suites>
                <file>suites.xml</file>
            </bespoke_suites>
            <suites>
                <file>suites.xml</file>
            </suites>
        </updates>
    </layout>
</adminhtml>

10
  • can you add the config.xml file?
    – Marius
    Commented Nov 9, 2015 at 8:16
  • @Marius updated config.xml file Commented Nov 9, 2015 at 8:20
  • @Marius, i created table manually.Table is not creating when i execute script. Commented Nov 9, 2015 at 8:22
  • can you add menu in config.xml or adminhtml.xml file?
    – Abdul
    Commented Nov 9, 2015 at 9:43
  • @Abdul ya,already there in adminhtml.xml Commented Nov 9, 2015 at 9:49

1 Answer 1

0

There are some issues with your config file.

<resourceModel>suites_resource</resourceModel>

should be

<resourceModel>bespoke_suites_resource</resourceModel>

and

    <bespoke_suites_resource>
        <class>Bespoke_Suites_Resource</class>
        <entities>
            <suites>
                <table>bespoke_suites</table>
            </suites>
        </entities>
    </bespoke_suites_resource>

Should be

    <bespoke_suites_resource>
        <class>Bespoke_Suites_Model_Resource</class>
        <entities>
            <suites>
                <table>bespoke_suites</table>
            </suites>
        </entities>
    </bespoke_suites_resource>

and I'm not sure you need this:

<blocks>
    <adminhtml>
        <rewrite>
            <bespoke_suites_grid>Bespoke_Suites_Block_Adminhtml_Bespoke_Suites_Grid</bespoke_suites_grid>
        </rewrite>
    </adminhtml>
</blocks>
5
  • ok,let me check Commented Nov 9, 2015 at 8:23
  • No Marius,if i change config.xml file,getting fatal error. Commented Nov 9, 2015 at 8:30
  • I have no other idea. Check the logs maybe.
    – Marius
    Commented Nov 9, 2015 at 8:31
  • @marian Is it because i created table manually? Commented Nov 9, 2015 at 8:34
  • I don't think that's the problem.
    – Marius
    Commented Nov 9, 2015 at 8:41

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.