Adminhtml MySQL – Error Getting Data from Custom Table in Grid View

adminhtmlMySQL

I'm using Magento 1.9.0.1 and i'm working on new custom magento extension.

Let me show you the files i think it is important to be shown for my question.

This is what i have in: /app/code/community/VivasIndustries/SmsNotification/etc/config.xml:

<?xml version="1.0"?>
<config>
  <modules>
    <VivasIndustries_SmsNotification>
      <version>0.1.0</version>
    </VivasIndustries_SmsNotification>
  </modules>
  <global>
    <models>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Model</class>
            <resourceModel>vivasindustries_smsnotification_resource</resourceModel>
        </smsnotification>
        <vivasindustries_smsnotification_resource>
        <class>VivasIndustries_SmsNotification_Model_Resource</class>
        <entities>
            <smsnotification>
            <table>VivasIndustries_SmsNotification</table>
            </smsnotification>
        </entities>
        </vivasindustries_smsnotification_resource>
    </models>
    <resources>
        <smsnotification_setup>
            <setup>
                <module>VivasIndustries_SmsNotification</module>
            </setup>
            <connection>
                 <use>core_setup</use>
             </connection>
        </smsnotification_setup>
        <smsnotification_read>
            <connection>
                <use>core_read</use>
            </connection>
        </smsnotification_read>
        <smsnotification_write>
            <connection>
                <use>core_write</use>
            </connection>
        </smsnotification_write>
    </resources>    
    <events>
        <sales_order_save_after>
            <observers>
                <vivasindustries_smsnotification>
                    <class>smsnotification/observer</class>
                    <method>orderSaved</method>
                </vivasindustries_smsnotification>
            </observers>
        </sales_order_save_after>
    </events>
    <helpers>
        <smsnotification>
            <class>VivasIndustries_SmsNotification_Helper</class>
        </smsnotification>
    </helpers>
    <blocks>
        <smsnotification>
             <class>VivasIndustries_SmsNotification_Block</class>
        </smsnotification>
    </blocks>
  </global>
  <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <vivas>
                                        <title>Vivas - All</title>
                                    </vivas>
                                </children>
                            </config>
                        </children>
                    </system>
                </children>
            </admin>
        </resources>
    </acl>
    </adminhtml>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <VivasIndustries_SmsNotification before="Mage_Adminhtml">VivasIndustries_SmsNotification_Adminhtml</VivasIndustries_SmsNotification>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>  

Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/Block/Adminhtml/Sales/Status/Grid.php:

<?php

class VivasIndustries_SmsNotification_Block_Adminhtml_Sales_Status_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('smsnotification_grid');
        $this->setDefaultSort('id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }


protected function _prepareCollection()
  {
      $collection = Mage::getResourceModel('smsnotification/smsnotification_collection');
      $this->setCollection($collection);
      return parent::_prepareCollection();
  }


protected function _prepareColumns()
  {
      $this->addColumn('id', array(
          'header'    => Mage::helper('smsnotification')->__('ID'),
          'align'     =>'right',
          'width'     => '50px',
          'index'     => 'id',
      ));

      $this->addColumn('Name', array(
          'header'    => Mage::helper('smsnotification')->__('Name'),
          'align'     =>'left',
          'index'     => 'Name',
      ));    

      return parent::_prepareColumns();
  }

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

I have custom table named VivasIndustries_SmsNotification and here is the structure of that table:

enter image description here

I want this data to be displayed in the grid table, but i receive the following error so far:

Fatal error: Call to a member function getReadConnection() on a non-object in /public_html/store/app/code/core/Mage/Core/Model/Resource/Db/Collection/Abstract.php on line 134

Let me show what i have in some other files which i think can be important for this error.

I have in: /app/code/community/VivasIndustries/SmsNotification/Model/SmsNotification.php:

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

}

Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/Model/Resource/Smsnotification.php:

<?php
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification extends Mage_Core_Model_Resource_Db_Abstract
{
    /**
     * Initialize resource model
     *
     * @return void
     */
    public function _construct()
    {
        $this->_init('smsnotification/smsnotification','id');
    }
}

Here is what i have in: /app/code/community/VivasIndustries/SmsNotification/Model/Resource/Smsnotification/Collection.php:

<?php 
class VivasIndustries_SmsNotification_Model_Resource_Smsnotification_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract{
    protected function _constuct(){
        $this->_init('smsnotification/smsnotification');    
    }
}

Can you please help me out resolve this error?
I simply want to display the data from VivasIndustries_SmsNotification in a grid table in a page created by me in the Admin panel.

Thanks in advance!

Best Answer

Your problem is probably here:

I have in:     /app/code/community/VivasIndustries/SmsNotification/Model/SmsNotification.php:

<?php
class VivasIndustries_SmsNotification_Model_Smsnotification extends extends     Mage_Core_Model_Abstract

You have a case error and a typo. You have two "extends" and based on your directory structure your class should read:

class VivasIndustries_SmsNotification_Model_SmsNotification extends     Mage_Core_Model_Abstract
Related Topic