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?
Mage_Adminhtml_block_Widget_Grid_Container
_prepareLayout
is largely unnecessary unless you need to re-map your grid file location.