Magento Fatal Error – Fix setSaveParametersInSession() on a Non-Object

magento-1.7magento-1.8magento-1.9php-5.4

I tried to create an admin grid on magento.Get the error while click on the admin menu setSaveParametersInSession() on a non-object.

My Config.xml : path(\app\code\local\ORD\UpdatePro\etc)

<admin>
 <routers>
     <updatepro>
        <use>admin</use>
        <args>
           <module>ORD_UpdatePro</module>
           <frontName>admintest</frontName>
        </args>
     </updatepro>
  </routers>
</admin>
<adminhtml>
   <layout>
      <updates>
          <updatepro>
              <file>updatepro.xml</file>
           </updatepro>
      </updates>
   </layout>
   <menu>
      <updatepro translate="title" module="adminhtml">
         <title>updatepro</title>
         <sort_order>100</sort_order>
         <children>
             <set_time>
                   <title>Report</title>
                   <sort_order>0</sort_order>
                   <action>admintest/adminhtml_index</action>
              </set_time>

          </children>
       </updatepro>
   </menu>
</adminhtml>

My IndexController.php : Path(\app\code\local\ORD\UpdatePro\controllers\Adminhtml)

class ORD_UpdatePro_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
protected function _initAction()
{
    $this->loadLayout()->_setActiveMenu('updatepro/set_time')
            ->_addBreadcrumb('updatepro Manager','updatepro Manager');
   return $this;
 }
//END of initaction
public function indexAction()
  {
     $this->_initAction();
     $this->renderLayout();
  }
}

My Block Class Grid.php : Path(\app\code\local\ORD\UpdatePro\Block\Adminhtml)

class ORD_UpdatePro_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container
{ 
  public function __construct(){
     $this->_controller = 'adminhtml_grid';
     $this->_blockGroup = 'updatepro';
     $this->_headerText = 'Adressbook management';
     $this->_addButtonLabel = 'Add a contact';
     parent::__construct();
 }
}

My Layout file updatepro.xml : Path(\app\design\adminhtml\default\default\layout)

<?xml version="1.0" ?>
   <layout version="0.1.0">
   <updatepro_adminhtml_index_index>
     <reference name="content">
      <block type="updatepro/adminhtml_grid"  name="updatepro" template="updatepro/afficher.phtml" />
    </reference>
   </updatepro_adminhtml_index_index>
</layout>

while click on the admin panel menu link i got the below error message

Fatal error: Call to a member function setSaveParametersInSession() on a non-object in C:\xampp\htdocs\staging_furryfriends\app\code\core\Mage\Adminhtml\Block\Widget\Grid\Container.php on line 69

it was a common error and found in many threads, Followed every steps carefully, unfortunately i am unable to figure out the problem and what was the error.
Expecting your kind explanation if any one can help me on this topic.

Best Answer

Take a look at [How to create a custom grid from scratch][1] and custom module with custom database table

Grid.php : Incorrect and missing

class <Namespace>_<Module>_Block_Adminhtml_<Module> extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_controller = 'adminhtml_<module>';
        $this->_blockGroup = '<module>';
        $this->_headerText = Mage::helper('<module>')->__('Item Manager');
        $this->_addButtonLabel = Mage::helper('<module>')->__('Add Item');
        parent::__construct();
    }
}


class <Namespace>_<Module>_Block_Adminhtml_<Module>_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('<module>Grid');
        // This is the primary key of the database
        $this->setDefaultSort('<module>_id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }
Related Topic