2

i'm using Magento 1.9.0.1.

I'm trying to display data from a custom MySQL table to a grid table in a custom admin panel page.

Here is the structure of the table from which i want to display the data. The table is called - VivasIndustries_SmsNotification:

enter image description here

Right now i have this result:

enter image description here

As you can see no table is created and no data is displayed.

Now i'm going to show you what i have in my extension files:

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/Model/SmsNotification.php:

<?php
class VivasIndustries_SmsNotification_Model_SmsNotification 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 _construct(){
        $this->_init('smsnotification/smsnotification');    
    }
}

And last and maybe most important:

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('Receiver', array(
              'header'    => Mage::helper('smsnotification')->__('Receiver'),
              'align'     =>'left',
              'index'     => 'Receiver',
          ));    

          return parent::_prepareColumns();
    }

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

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

<?php

class VivasIndustries_SmsNotification_Block_Adminhtml_Sales_Status extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_blockGroup = 'smsnotification';
        $this->_controller = 'adminhtml_sales_status';
        $this->_headerText = Mage::helper('smsnotification')->__('Send SMS on Order Status Changes');

        parent::__construct();
        $this->_removeButton('add');
    }
}

Please help me out to display the data from VivasIndustries_SmsNotification and why now i get blank page, where is my mistake?

Thanks in advance!

3

You may be missing two things to get your Grid to show up.

Add this file:

app/code/community/VivasIndustries/SmsNotification/Block/Adminhtml/Sales/Status.php

<?php
class VivasIndustries_SmsNotification_Block_Adminhtml_Sales_Status extends     Mage_Adminhtml_Block_Widget_Grid_Container
{

public function __construct()
{

    $this->_controller = 'adminhtml_sales_status';
    $this->_blockGroup = 'smsnotification';
    $this->_headerText = Mage::helper('smsnotification')->__('SMS Notifications');
    parent::__construct();
}


protected function _prepareLayout()
{
   $this->setChild( 'grid',
       $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
       $this->_controller . '.grid')->setSaveParametersInSession(true) );
   return parent::_prepareLayout();
}

}

And this file:

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

<layout>
    <adminhtml_smsnotification_index>
        <reference name="content">
            <block type="smsnotification/adminhtml_sales_status" name="smsnotification" />
        </reference>
    </adminhtml_smsnotification_index>
</layout>

In your etc/config.xml, add this in the <adminhtml> tag:

  <layout>
        <updates>
            <smsnotification>
                <file>smsnotification.xml</file>
            </smsnotification>
        </updates>
    </layout>
  • No.. no there was a mistake posting it here. There is no doube <?PHP tags in the real file and the problem is still the same. – Venelin Vasilev Feb 8 '15 at 0:42
  • Edited my answer. – seanbreeden Feb 8 '15 at 0:55
  • When i do that i got error: Fatal error: Call to a member function getCollection() on a non-object in /home/superweb/public_html/store/app/code/community/VivasIndustries/SmsNotification/Block/Adminhtml/Sales/Status/Grid.php on line 18 – Venelin Vasilev Feb 8 '15 at 0:58
  • On line 18 is the following content $collection = Mage::getModel('smsnotification/smsnotification')->getCollection(); – Venelin Vasilev Feb 8 '15 at 0:59
  • Ok change that back then. Quick question: do you have an xml in app/design/adminhtml/default/default/layout/ for your extension? – seanbreeden Feb 8 '15 at 1:00

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.