1

I have created a custom module one part is working fine that is adminform now i have create a grid to show all the data saved in database. But all i get is blank page.

Here is my grid.php file:

<?php

   class OptFirst_ReviewMyCompany_Block_Adminhtml_Review_Grid extends
Mage_Adminhtml_Block_Widget_Grid
     {


      public function __construct()
       {
         parent::__construct();
         $this->setId('reviewGrid');
         $this->setDefaultSort('id_optfirst_reviewmycompany');
         $this->setDefaultDir('ASC');
         $this->setSaveParametersInSession(true);
       }

      protected function _prepareCollection()
       {
         $collection = Mage::getModel('optfirst_reviewmycompany/review')->getCollection();
         //print_r($collection);
         $this->setCollection($collection);
         return parent::_prepareCollection();
       }

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

        $this->addColumn('name', array(
        'header' => Mage::helper('optFirst_reviewMyCompany')->__('Google'),
        'align' => 'left',
        'index' => 'name',
        'width' => '50px',
        ));


    $this->addColumn('content', array(
        'header' => Mage::helper('optFirst_reviewMyCompany')->__('Twitter'),
        'width' => '150px',
        'index' => 'content',
        ));
      return parent::_prepareColumns();
     }
   }

And here is my controller:

  <?php

       class OptFirst_ReviewMyCompany_Adminhtml_ReviewController extends Mage_Adminhtml_Controller_action
        {

          public functio  indexAction() {
            $this->loadLayout();
            $this->renderLayout();

        }
       public function gridAction()
        {
         $this->loadLayout();
         $this->getResponse()->setBody(
         $this->getLayout()->createBlock('optfirst_reviewmycompany/adminhtml_review_grid')->toHtml()
         );
        }
       }

And here is my confix.xml

  <?xml version="1.0"?>
   <config>
<modules>
    <OptFirst_ReviewMyCompany>
        <version>1.0.0</version>
    </OptFirst_ReviewMyCompany>
</modules>

<global>
    <blocks>
        <optfirst_reviewmycompany>
            <class>OptFirst_ReviewMyCompany_Block</class>
        </optfirst_reviewmycompany>
    </blocks>

    <helpers>
        <optfirst_reviewmycompany>
            <class>OptFirst_ReviewMyCompany_Helper</class>
        </optfirst_reviewmycompany>
    </helpers>

    <models>         
        <optfirst_reviewmycompany>
            <class>OptFirst_ReviewMyCompany_Model</class>
            <resourceModel>optfirst_reviewmycompany_resource</resourceModel>
        </optfirst_reviewmycompany>
        <optfirst_reviewmycompany_resource>
            <class>OptFirst_ReviewMyCompany_Model_Resource</class>
            <entities>
                <review>
                    <table>optfirst_reviewmycompany</table>
                </review>
            </entities>
        </optfirst_reviewmycompany_resource>
    </models>

    <resource>
        <optfirst_reviewmycompany_setup>
            <setup>
                <module>OptFirst_ReviewMyCompany</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </optfirst_reviewmycompany_setup>
        <optfirst_reviewmycompany_write>
            <connection>
                <use>core_write</use>
            </connection>
        </optfirst_reviewmycompany_write>
        <optfirst_reviewmycompany_read>
            <connection>
                <use>core_read</use>
            </connection>
        </optfirst_reviewmycompany_read>
    </resource>
</global>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <optfirst_reviewmycompany after="Mage_Adminhtml">OptFirst_ReviewMyCompany_Adminhtml</optfirst_reviewmycompany>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

<adminhtml>
    <layout>
        <updates>
            <optfirst_reviewmycompany>
                <file>optfirst_reviewmycompany.xml</file>
            </optfirst_reviewmycompany>
        </updates>
        <updates>
            <review>
                <file>review.xml</file>
            </review>
        </updates>
    </layout>
    <translate>
        <modules>
            <optfirst_reviewmycompany>
                <files>
                    <default>OptFirst_ReviewMyCompany.csv</default>
                </files>
            </optfirst_reviewmycompany>
        </modules>
    </translate>
</adminhtml>

<default>
    <optfirst_reviewmycompany>
        <general>
            <default_sort_by><![CDATA[position]]></default_sort_by>
        </general>
    </optfirst_reviewmycompany>
</default>

My Helper Class in OptFirst/ReviewMyCompany/Helper/Data.php

     <?php
      class OptFirst_ReviewMyCompany_Helper_Data extends Mage_Core_Helper_Abstract
         {

         }

enter image description here

Can you please check what is wrong and why its not showing the grid container?

1

After review you coding there were three mistake in that

config.xml

<?xml version="1.0"?>
<config>
    <menu>
        <optfirst translate="title" module="optfirst_reviewmycompany">
            <title>Review My Company</title>
            <sort_order>90</sort_order>
            <children>
                <form translate="title" module="optfirst_reviewmycompany">
                    <title>Form</title>
                    <sort_order>10</sort_order>
                    <action>adminhtml/adminform</action>
                </form>
                  <items module="optfirst_reviewmycompany">
                        <title>Manage Social Icons</title>
                        <sort_order>0</sort_order>
                    <action>adminhtml/review/index</action>
                    </items>
            </children>
        </optfirst>
    </menu>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <optfirst>
                        <title>Optfirst</title>
                        <sort_order>90</sort_order>
                        <children>
                            <form>
                                <title>Form</title>
                                <sort_order>10</sort_order>
                            </form>
                        </children>
                    </optfirst>
                </children>
            </admin>
        </resources>
    </acl>
</config>

optfirst_reviewmycompany.xml

<?xml version="1.0"?>
<layout version="1.0.0">

    <adminhtml_adminform_index>
        <update handle="editor"/>
        <reference name="content">
            <block type="optfirst_reviewmycompany/adminhtml_form_edit" name="adminform"/>
        </reference>
       <reference name="left">
            <block type="optfirst_reviewmycompany/adminhtml_form_edit_tabs" name="adminform_tabs"/>
        </reference>
    </adminhtml_adminform_index>

    <adminhtml_review_index>
        <reference name="content">
            <block type="optfirst_reviewmycompany/adminhtml_review" name="review" />
        </reference>
    </adminhtml_review_index>

</layout>

ReviewController.php

<?php

class OptFirst_ReviewMyCompany_Adminhtml_ReviewController extends Mage_Adminhtml_Controller_action
{

    public function indexAction() {
        $this->loadLayout();
                $this->renderLayout();               
    }

    public function gridAction()
    {  //this action is used for ajax request you are calling it directly


                $this->getResponse()->setBody(
                $this->getLayout()->createBlock('optfirst_reviewmycompany/adminhtml_review_grid')->toHtml()
                );

    }


 }

Review.php

<?php
class OptFirst_ReviewMyCompany_Block_Adminhtml_Review extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_controller = 'adminhtml_review';
        $this->_blockGroup = 'optfirst_reviewmycompany';
        $this->_headerText = Mage::helper('optfirst_reviewmycompany')->__('Review Manager');
        $this->_addButtonLabel = Mage::helper('optfirst_reviewmycompany')->__('Add Review');
        parent::__construct();
    }

}
  • So indexAction is working fine, it is showing correct layout i have just echo a thing there. You change the action to index method but we need the action to gridAction method so it will show the grid page instead of showing index page.. @Qaisar Satti – Xabby Nov 30 '16 at 10:13
  • @Xabby gridaction is used when you apply filter to gird then layout are update from gridaction. If you search in grid the while page is update only grid is update that time called the gridAction. I fully tested you code then gave you solution – Qaisar Satti Nov 30 '16 at 10:15
4

Your helpers calls in your Grid.php are wrong.

You need to replace:

Mage::helper('optFirst_reviewMyCompany')

With :

Mage::helper('optfirst_reviewmycompany')

The value inside the Mage::helper method should match what you've declared in your config.xml in your case:

<helpers>
    <optfirst_reviewmycompany>
        <class>OptFirst_ReviewMyCompany_Helper</class>
    </optfirst_reviewmycompany>
</helpers>
  • I have tried with following solutions but still showing the same results also i have attached the screenshot of my screen that what it looks like: 1- Mage::helper('optfirst_reviewmycompany')->__('Facebook'), 2- Mage::helper('adminhtml')->__('Facebook'), – Xabby Nov 28 '16 at 12:13
1

I thin you are missing the grid container

class OptFirst_ReviewMyCompany_Block_Adminhtml_Review extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_controller = 'adminhtml_review';
        $this->_blockGroup = 'review';
        $this->_headerText = Mage::helper('test')->__('Review Manager');
        $this->_addButtonLabel = Mage::helper('advancecms')->__('Add Review');
        parent::__construct();
    }
}

that were called in

<adminhtml_review_grid>
    <reference name="content">
        <block type="reviewMyCompany/adminhtml_review" name="review" />
    </reference>
</adminhtml_review_grid>
0
<? xml version = "1.0" ?>
 <layout version="0.1.0">
    <adminhtml_reviewmycompany_review_grid>
        <reference name="content">
            <block type="reviewmycompany/adminhtml_review_grid" name="review" />
        </reference>
    </adminhtml_reviewmycompany_review_grid>
</layout>

layout XML node

adminRoute_moduleName_contromlerName_ActionName

refers to route

adminRoute/moduleName/contromlerName/ActionName

So

<adminhtml_reviewmycompany_review_grid>

will refer to

YOUR_ADMIN_ROUTE/reviewmycompany/review/grid

and resolve to the following method

OptFirst/ReviewMyCompany/Adminhtml/ReviewController -> gridAction

  • When i just echo a string it shows but when i load grid it shows error here is my ReviewController.php public function gridAction() { $this->loadLayout(); $this->renderLayout(); echo "Hello"; // $this->getResponse()->setBody( //$this->getLayout()->createBlock('optfirst_reviewmycompany/adminhtml_review_grid')->toHtml() //); } } – Xabby Nov 26 '16 at 17:25
  • What's the error message say? – Weaves81 Nov 26 '16 at 17:34
  • this is the error: Class 'Mage_Reviewmycompany_Helper_Data' not found in C:\xampp\htdocs\magento_dev\app\Mage.php on line 547 @Weaves81 – Xabby Nov 26 '16 at 18:11
  • So In your block you've called Mage::helper('reviewmycompany')->__('ID'). Does OptFirst/ReviewMyCompany/Helper/Data.php exist? If not just create it and extend Mage_Core_Helper_Abstract. it can just be an empty class. – Weaves81 Nov 26 '16 at 18:16
  • the error is because of You have not added helper file in your module, just create a file in helper folder with class name OptFirst_Reviewmycompany_Helper_Data extending Mage_Core_Helper_Abstract – Piyush Nov 26 '16 at 18:16
0

in your grid.php file helper is wrong in every where

please change your grid.php with below

<?php

   class OptFirst_ReviewMyCompany_Block_Adminhtml_Review_Grid extends
Mage_Adminhtml_Block_Widget_Grid
     {


      public function __construct()
       {
         parent::__construct();
         $this->setId('reviewGrid');
         $this->setDefaultSort('id_optfirst_reviewmycompany');
         $this->setDefaultDir('ASC');
         $this->setSaveParametersInSession(true);
       }

      protected function _prepareCollection()
       {
         $collection = Mage::getModel('optfirst_reviewmycompany/review')->getCollection();
         //print_r($collection);
         $this->setCollection($collection);
         return parent::_prepareCollection();
       }

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

        $this->addColumn('name', array(
        'header' => Mage::helper('optfirst_reviewmycompany')->__('Google'),
        'align' => 'left',
        'index' => 'name',
        'width' => '50px',
        ));


    $this->addColumn('content', array(
        'header' => Mage::helper('optfirst_reviewmycompany')->__('Twitter'), 
        'width' => '150px',
        'index' => 'content',
        ));
      return parent::_prepareColumns();
     }
   }
  • Ok that is updated but still not any luck can you please check the Block section class OptFirst_ReviewMyCompany_Block_Adminhtml_Review extends Mage_Adminhtml_Block_Widget_Grid_Container { public function __construct() { $this->_controller = 'adminhtml_review'; $this->_blockGroup = 'review'; $this->_headerText = Mage::helper('optfirst_reviewmycompany')->__('Review Manager'); $this->_addButtonLabel = Mage::helper('optfirst_reviewmycompany')->__('Add Review'); parent::__construct(); } – Xabby Nov 29 '16 at 13:01
  • @Xabby after that change error is same or some different error you got – Murtuza Zabuawala Nov 29 '16 at 13:08
  • Its still not showing the correct layout of the Grid. its same as the screenshot attached above with the question – Xabby Nov 29 '16 at 13:41

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.