I have made a custom module for admin in magento. Its namespace is "Assel" and module name is "Character".
This is my config.xml file
<?xml version="1.0"?>
<config>
<modules>
<Assel_Character>
<version>1.0.0</version>
</Assel_Character>
</modules>
<admin>
<routers>
<character>
<use>admin</use>
<args>
<module>Assel_Character</module>
<frontName>character</frontName>
</args>
</character>
</routers>
</admin>
<adminhtml>
<menu>
<cms>
<children>
<character translate="title" module="character">
<title>Characters</title>
<sort_order>91</sort_order>
<action>character/adminhtml_character</action>
</character>
</children>
</cms>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<character>
<title>Character</title>
</character>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<models>
<character>
<class>Assel_Character_Model</class>
<resourceModel>character_mysql4</resourceModel>
</character>
<character_mysql4>
<class>Assel_Character_Model_Mysql4</class>
<entities>
<character>
<table>character</table>
</character>
</entities>
</character_mysql4>
</models>
<resources>
<character_setup>
<setup>
<module>Assel_Character</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</character_setup>
<character_write>
<connection>
<use>core_write</use>
</connection>
</character_write>
<character_read>
<connection>
<use>core_read</use>
</connection>
</character_read>
</resources>
<blocks>
<character>
<class>Assel_Character_Block</class>
</character>
</blocks>
<helpers>
<character>
<class>Assel_Character_Helper</class>
</character>
</helpers>
</global>
</config>
This is my Grid_Container class file named "Character.php" in Assel_Character_Block_Adminhtml folder.
<?php
class Assel_Character_Block_Adminhtml_Character extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_controller = 'adminhtml_character';
$this->_blockGroup = 'character';
$this->_headerText = Mage::helper('character')->__('Characters');
$this->_addButtonLabel = Mage::helper('character')->__('Add New Character');
parent::__construct();
}
}
this is my Grid.php file in Assel_Character_Block_Adminhtml_Character folder.
<?php
class Assel_Character_Block_Adminhtml_Character_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
public function __construct()
{
parent::__construct();
$this->setId('characterGrid');
$this->setDefaultSort('id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection()
{
$collection = Mage::getModel('character/character')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns()
{
$this->addColumn('id', array(
'header' => Mage::helper('character')->__('ID'),
'align' => 'center',
'width' => '10px',
'index' => 'id',
));
$this->addColumn('name', array(
'header' => Mage::helper('character')->__('Name'),
'align' => 'center',
'index' => 'name',
));
$this->addColumn('alt_name', array(
'header' => Mage::helper('character')->__('Alt. Name'),
'align' => 'center',
'index' => 'alt_name',
));
$this->addColumn('image', array(
'header' => Mage::helper('character')->__('Image'),
'align' => 'center',
'index' => 'image',
));
$this->addColumn('action',
array(
'header' => Mage::helper('character')->__('Action'),
'width' => '10',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('character')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
return parent::_prepareColumns();
}
protected function _prepareMassaction() {
$this->setMassactionIdField('id');
$this->getMassactionBlock()->setFormFieldName('character');
$this->getMassactionBlock()->addItem('delete', array(
'label' => Mage::helper('character')->__('Delete'),
'url' => $this->getUrl('*/*/massDelete'),
'confirm' => Mage::helper('character')->__('Are you sure?')
));
array_unshift($statuses, array('label'=>'', 'value'=>''));
$this->getMassactionBlock()->addItem('status', array(
'label'=> Mage::helper('character')->__('Change status'),
'url' => $this->getUrl('*/*/massStatus', array('_current'=>true)),
'additional' => array(
'visibility' => array(
'name' => 'status',
'type' => 'select',
'class' => 'required-entry',
'label' => Mage::helper('character')->__('Status'),
'values' => $statuses
)
)
));
return $this;
}
public function getRowUrl($row)
{
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
}
This is the my controller file named CharacterController.php in Assel_Character_controllers_Adminhtml folder.
class Assel_Character_Adminhtml_CharacterController extends Mage_Adminhtml_Controller_Action
{
protected function _initAction() {
$this->loadLayout()
->_setActiveMenu('character')
->_addBreadcrumb(Mage::helper('adminhtml')->__('Characters Manager'), Mage::helper('adminhtml')->__('Character Manager'));
return $this;
}
public function indexAction() {
$this->_initAction()
->_addContent($this->getLayout()->createBlock('character/adminhtml_character'))
->renderLayout();
}
}
This is screenshot of my admin.
I cann't figure out what is wrong there in code so grid is not showing in backend.
Anyone Please look above code and please tell me where I am wrong..
$collection = Mage::getModel('character/character')->getCollection();
and make sure it holds a collection