Thanks to @PHP Weblineindia for sharing a link for this tutorial http://navaneeth.me/creating-magento-extension-with-custom-database-table/#comment-8147.
I followed almost every details given by this tutorial however I can't display the table grid.
UPDATE: Upon Debugging my model collection has a problem
Another UPDATE: I update all the resource model and collection and extend them to this
Mage_Core_Model_Resource_Db_Abstract -> resource model
Mage_Core_Model_Resource_Db_Collection_Abstract -> Collection model
The good thing is that. I can now add new data to the database.
BUT the main problem still the same, no grid displayed.
I've tried simple data retrieve in magento front end but it give me Fatal error: Call to a member function load() on a non-object.
I'm still new to magento and there are lot of mysteries that I need to discover.
MODEL
app/code/local/Rts/Pmadmin/Model/Pmadmin.php
class Rts_Pmadmin_Model_Pmadmin extends Mage_Core_Model_Abstract {
protected function _construct()
{
$this->_init('pmadmin/pricematrix');
}
}
app/code/local/Rts/Pmadmin/Model/Mysql4/Resource/Pmadmin.php
class Rts_Pmadmin_Model_Mysql4_Resource_Pmadmin extends Mage_Core_Model_Resource_Db_Abstract {
protected function _construct()
{
$this->_init('pmadmin/pmadmin', 'pmadmin_id');
}
}
app/code/local/Rts/Pmadmin/Model/Mysql4/Resource/Collection.php
class Rts_Pmadmin_Model_Mysql4_Resource_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract {
public function _construct()
{
parent::_construct();
$this->_init('pmadmin/pmadmin');
}
}
These are the codes.
UPDATED config.xml
<global>
<helpers>
<pmadmin>
<class>Rts_Pmadmin_Helper</class>
</pmadmin>
</helpers>
<blocks>
<pmadmin>
<class>Rts_Pmadmin_Block</class>
</pmadmin>
</blocks>
<models>
<pmadmin>
<class>Rts_Pmadmin_Model</class>
<resourceModel>pmadmin_resource</resourceModel>
</pmadmin>
<pmadmin_resource>
<class>Rts_Pmadmin_Model_Resource</class>
<entities>
<pmadmin>
<table>pmadmin</table>
</pmadmin>
</entities>
</pmadmin_resource>
</models>
<resources>
<pmadmin_setup>
<setup>
<module>Rts_Pmadmin</module>
<class>Rts_Pmadmin_Model_Mysql4_Resource_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</pmadmin_setup>
<pmadmin_write>
<connection>
<use>core_write</use>
</connection>
</pmadmin_write>
<pmadmin_read>
<connection>
<use>core_read</use>
</connection>
</pmadmin_read>
</resources>
</global>
UPDATE: Content block
class Rts_Pmadmin_Block_Adminhtml_Pmadmin_Grid extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId('pmadmingrid');
$this->setDefaultSort('pmadmin_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
$this->setUseAjax(true);
}
protected function _prepareCollection() {
$collection = Mage::getModel('pmadmin/pmadmin')->getCollection();
// print_r($collection); exit();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('pricematrix_id', array(
'header' => Mage::helper('pmadmin')->__('ID'),
'align' => 'right',
'width' => '10px',
'index' => 'pricematrix_id',
));
$this->addColumn('title', array(
'header' => Mage::helper('pmadmin')->__('Title'),
'align' => 'left',
'index' => 'title',
'width' => '50px',
));
$this->addColumn('short_description', array(
'header' => Mage::helper('pmadmin')->__('Description'),
'width' => '150px',
'index' => 'short_description',
));
$this->addColumn('file_path', array(
'header' => Mage::helper('pmadmin')->__('File Path'),
'width' => '150px',
'index' => 'file_path',
));
$this->addColumn('customer_group', array(
'header' => Mage::helper('pmadmin')->__('Customer Group'),
'width' => '150px',
'index' => 'customer_group',
));
$this->addColumn('creation_time', array(
'header' => Mage::helper('pmadmin')->__('Posted On'),
'width' => '150px',
'index' => 'creation_time',
));
return parent::_prepareColumns();
}
public function getRowUrl($row) {
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
public function getGridUrl()
{
return $this->getUrl('*/*/grid', array('_current'=>true));
}
}
PROBLEM:
No grid is displayed only the header title and the add button
When click add button, the forms are displayed however I can't add new Item
Model Collection return "bool(false)" after var dump
QUESTION:
Can you help me spot the problem?
Thanks
See Question&Answers more detail:
os