2

I am trying to add a grid to the admin area, but I am receiving a blank content area (although the wrapper is displaying i.e. the _headerText and _addButtonLabel, the grid itself does not display). I have checked an re checked my code (error reporting is on but I get no errors).

I have tried

$mod = Mage::getModel('prefs/prefsformelements')->getData();
var_dump($mod);

and it tells me the data array is is empty (if there was a problem with the model, surely there would be an error returned?) is there something wrong with my code which for block? (I have provided the code for the grid as I would expect to get an empty grid if there is no data being received).

class Ps_Prefs_Adminhtml_AdminformsController
extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
    $this->loadLayout();
    $this->_addContent($this->getLayout()->createBlock('prefs/adminhtml_forms'));
    $this->renderLayout();
}
}

.

class Ps_Prefs_Block_Adminhtml_Forms
extends Mage_Adminhtml_block_Widget_Grid_Container
{
public function _construct()
{
    $this->_controller = 'adminhtml_forms';//path to block
    $this->_blockGroup = 'prefs';//module name
    $this->_headerText = $this->__( 'Form Fields' );
    $this->_addButtonLabel = $this->__( 'New Field' );
    parent::_construct();
}

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

.

class Ps_Prefs_Block_Adminhtml_Forms_Grid
extends Mage_Adminhtml_Block_Widget_Grid
{
public function _construct()
{
    parent::_construct();
    $this->setId('prefs_adminforms_index');
    $this->setDefaultSort('fieldname');
    $this->setDefaultDir('ASC');
    $this->setSaveParametersInSession(TRUE);
    $this->setUseAjax(TRUE);

}

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

protected function _prepareColumns()
{
    $this->addColumn('fieldname', array(
       'header'  =>  $this->__('fieldname'),
       'index'   => 'fieldname'
    ));

    $this->addColumn('idform_elements', array(
        'header'    =>  $this->__('ID'),
        'align'     => 'left',
        'width'     => '50px',
        'index'     => 'idform_elements',//name of db column
    ));

    parent::_prepareColumns();
}

===

EDIT

===

this is the second page that I am trying to a grid to within this module. When I pull the data from the database for grid one I use

$this->_init('prefs/prefs');

but for this model ive been forced to use

$this->_init('ps_prefs/prefsformelements');

without the namespace I get a cant find entity config error, could this have an affect on my current problem?

===

EDIT

===

Still trying to track down the problem and I have found that if I add a simple echo command to Ps_Prefs_Block_Adminhtml_Forms_Grid::_prepareColumns() it is displayed. So would I be right in assuming I have done something wrong with the $this->addColumn commands? or is there something else going on here?

  • I'm not sure that this is your exact problem, but this block is mis-capitalized: Mage_Adminhtml_block_Widget_Grid_Container – philwinkle Oct 29 '13 at 15:35
  • Did this fix your problem? – philwinkle Oct 29 '13 at 15:37
  • no, I have made an edit to the bottom of the question to provide more information in the hope it will help – tony09uk Oct 29 '13 at 15:45
  • Another point here is that re-defining _prepareLayout is largely unnecessary unless you need to re-map your grid file location. – philwinkle Oct 29 '13 at 15:46
  • I have commented that out now. Nothing has changed. But I now understand what _prepareLayout is really used for :D – tony09uk Oct 29 '13 at 15:50
5

You've asked question with multiple possible answers, dependent on a level of site configuration that's hard to debug remotely.

I usually debug this things bottom up. It looks like you're trying to add block to main content area in the admin interface.

$this->_addContent($this->getLayout()->createBlock('prefs/adminhtml_forms'));

So, the first two things I'd check are

  • Can I add a text block to the content area

  • Can I instantiate my block

The answers to these questions will move you along to the next step of your debugging workflow.

Re: adding a text block -- test that with the following

$this->_addContent(
    $this->getLayout()->createBlock('core/text')->setText('<h1>Success</h1>')
);

You should see the word Success output to the content area.

Re: instantiating your block, test that with

$my_block = $this->getLayout()->createBlock('prefs/adminhtml_forms');
var_dump(get_class($my_block));

You should see your block's class name output to the screen. My guess is you'll see a boolean false for the later, pointing to a misconfigured block and/or a class with the wrong name/location.

  • Ive following your advice I and setText successfully and outputted my class name Ps_Prefs_Adminhtml_AdminformsController. I've edited my question, this is what ive added (i realise this may have an effect on the way I should debug). although the wrapper is displaying i.e. the _headerText and _addButtonLabel, the grid itself does not display – tony09uk Oct 30 '13 at 9:07
3

A quick one to check is if the module's output has been disabled under System > Configuration > Advanced > Disable Modules Output. If it is disabled for your module it will render a complete page with no errors and just empty where the grid should have been.

  • Tnx, you just saved at least 1 hour of debugging time :) – JohnyFree Jul 14 '16 at 15:38
0

I just came across this issue. My problem was bad config.xml tag structure, if:

<models>
    <mycompany_ordergrid>
            <class>Mycompany_OrderGrid_Model</class>
    </mycompany_ordergrid>
    <sales_resource>
        <rewrite>
            <order_grid_collection>Mycompany_OrderGrid_Model_Resource_Sales_Order_Grid_Collection</order_grid_collection>
        </rewrite>
    </sales_resource>
</models>

Is changed to:

<models>
    <mycompany_ordergrid>
            <class>Mycompany_OrderGrid_Model</class>
    </mycompany_ordergrid>
    <sales_resource>
        <rewrite>
            <order_grid_collection>Mycompany_OrderGrid_Model_Resource_Sales_Order_Grid_Collection
            </order_grid_collection>
        </rewrite>
    </sales_resource>
</models>

The order grid will silently fail to load.

  • Is the difference the newline? – Robbie Averill Aug 1 '16 at 23:04
  • Yes, new line before </order_grid_collection> – Anand Aug 3 '16 at 14:49

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.