1

I am creating a small admin module. When i did var_dump($collection) in my Grid.php file i get false value. Also i am not able to see the grid too.

Moreover, i am able to see my header text and button ie: Add Banner.

My module files are as below.

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Greeting_Greetingslider>
            <version>0.1.0</version>
        </Greeting_Greetingslider>
    </modules>
    <frontend>
        <routers>
            <greetingslider>
                <use>standard</use>
                <args>
                    <module>Greeting_Greetingslider</module>
                    <frontName>greetingslider</frontName>
                </args>
            </greetingslider>
        </routers>
    </frontend>
    <admin>
        <routers>
            <greetingslider>
                <use>admin</use>
                <args>
                    <module>Greeting_Greetingslider</module>
                    <frontName>greetingslider</frontName>
                </args>
            </greetingslider>
        </routers>
    </admin>
    <global>
        <helpers>
            <greetingslider>
                <class>Greeting_Greetingslider_Helper</class>
            </greetingslider>
        </helpers>
        <blocks>
            <greetingslider>
                <class>Greeting_Greetingslider_Block</class>
            </greetingslider>
        </blocks>
        <models>
            <greetingslider>
                <class>Greeting_Greetingslider_Model</class>
                <resourceModel>slider_mysql4</resourceModel>
            </greetingslider>
            <slider_mysql4>
                <class>Greeting_Greetingslider_Model_Mysql4</class>
                <entities>
                    <greetingslider>
                        <table>greetingslider</table>
                    </greetingslider>
                </entities>
            </slider_mysql4>
        </models>
        <resources>
            <greetingslider_setup>
                <setup>
                    <module>Greeting_Greetingslider</module>
                </setup>
                <connection>
                    <use>core_setup</use>
                </connection>
            </greetingslider_setup>
            <greetingslider_write>
                <connection>
                    <use>core_write</use>
                </connection>
            </greetingslider_write>
            <greetingslider_read>
                <connection>
                    <use>core_read</use>
                </connection>
            </greetingslider_read>
        </resources>
    </global>
    <adminhtml>
        <menu>
            <greetingslider module="greetingslider">
                <title>Greeting Slider</title>
                <sort_order>100</sort_order>
                <children>
                    <items module="greetingslider">
                        <title>Manage Banners</title>
                        <action>greetingslider/adminhtml_greetingslider</action>
                    </items>
                </children>
            </greetingslider>
        </menu>
        <acl>
            <resources>
                <all>
                    <title>Allow Everything</title>
                </all>
                <admin>
                    <children>
                        <greeting_greetingslider>
                            <title>Greeting Slider</title>
                            <sort_order>10</sort_order>
                        </greeting_greetingslider>
                    </children>
                </admin>
            </resources>
        </acl>
        <layout>
            <updates>
                <greetingslider>
                    <file>greetingslider.xml</file>
                </greetingslider>
            </updates>
        </layout>
    </adminhtml>
</config>

app/code/local/Greeting/Greetingslider/Model/Greetingslider.php

<?php
class Greeting_Greetingslider_Model_Greetingslider extends Mage_Core_Model_Abstract{
    public function _construct(){
        parent::_construct();
        $this->_init('greetingslider/greetingslider');
    }
}

app/code/local/Greeting/Greetingslider/Model/Mysql4/Greetingslider.php

<?php class Greeting_Greetingslider_Model_Mysql4_Greetingslider extends Mage_Core_Model_Mysql4_Abstract{
    public function _construct(){
        $this->_init('greetingslider/greetingslider','slide_id');
    } }

app/code/local/Greeting/Greetingslider/Model/Mysql4/Greetingslider/Collection.php

<?php
class Greeting_Greetingslider_Model_Mysql4_Greetingslider_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    public function _construct(){
        $this->_init('greetingslider/greetingslider');
    }
}

app/code/local/Greeting/Greetingslider/Block/Adminhtml/Greetingslider.php

<?php
class Greeting_Greetingslider_Block_Adminhtml_Greetingslider extends Mage_Adminhtml_Block_Widget_Grid_Container{
    public function __construct(){
        $this->_controller = 'adminhtml_greetingslider';
        $this->_blockGroup = 'greetingslider';
        $this->_headerText = Mage::helper('greetingslider')->__('Banner Manager');
        $this->_addButtonLabel = Mage::helper('greetingslider')->__('Add Banner');
        parent::__construct(); 
    }
}

app/code/local/Greeting/Greetingslider/Block/Adminhtml/Greetingslider/Grid.php

<?php
class Greeting_Greetingslider_Block_Adminhtml_Greetingslider_Grid extends Mage_Adminhtml_Block_Widget_Grid{
    public function __construct(){
        parent::__construct();
        $this->setId('greetingslider_grid');
        $this->setDefaultSort('slide_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }
    protected function _prepareCollection(){
        $collection = Mage::getModel('greetingslider/greetingslider')->getCollection();
        var_dump($collection);
        $this->setCollection($collection);
        return parent::_prepareCollection();
    } 
    protected function _prepareColumns(){
         $this->addColumn('slide_id', array(
            'header' => Mage::helper('greetingslider')->__('ID'),
            'align' => 'right',
            'width' => '10px',
            'index' => 'slide_id',
        ));
        return parent::_prepareColumns();
    }
    public function getRowUrl($row) {
        return $this->getUrl('*/*/edit', array('id' => $row->getId()));
    } 
}

app/code/local/Greeting/Greetingslider/controllers/Adminhtml/GreetinsliderController.php

<?php 
class Greeting_Greetingslider_Adminhtml_GreetingsliderController extends Mage_Adminhtml_Controller_action {
    protected function _initAction(){
        $this->loadLayout()->_setActiveMenu('greetingslider/greetingslider')->_addBreadcrumb(
            Mage::helper('adminhtml')->__('Banner Slider'),
            Mage::helper('adminhtml')->__('Slide Manager')
        );
        return $this;
    }
    public function indexAction(){
        $this->_initAction()->renderLayout();
    }
}

I am not able to figure out where is the mistake. Also i have a table in database named greetingslider

  • Is there any log errors present ? – Rajeev K Tomy Aug 20 '14 at 10:40
1

dexter,it may be issue with slider_mysql4 change to greetingslider_mysql4.

Check database name is greetingslider

| improve this answer | |
  • can I know why slider_mysql4 would make a problem here ? – Rajeev K Tomy Aug 20 '14 at 10:39
  • I had a misconception about it.. i thought we can name it anything, just the name of resourceModel and entity tags should be same.. anyways it is resolved now.. Thanks a lot @Amit... i wasted lot of my time on it.. – Dexter Aug 20 '14 at 10:44
  • @Dexter : Are you damn sure about this point? I still believe we can put any value there. Its just a reference for our resource model – Rajeev K Tomy Aug 20 '14 at 10:50
  • @Amit : can you confirm dexter's point ? I would like to know why it didnt work – Rajeev K Tomy Aug 20 '14 at 10:54
  • yes..it should be resoucemodel same should be same name as Model same as you describe your model same is greetingslider then your resource model is greetingslider_mysql4 or greetingslider_resource depends on resource type – Amit Bera Aug 20 '14 at 10:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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