【发布时间】:2016-02-18 10:10:44
【问题描述】:
感谢@PHP Weblineindia 分享本教程的链接http://navaneeth.me/creating-magento-extension-with-custom-database-table/#comment-8147。
我几乎遵循了本教程给出的所有细节,但是我无法显示表格网格。
更新:在调试我的模型集合时出现问题
另一个更新:我更新了所有资源模型和集合并将它们扩展到这个
Mage_Core_Model_Resource_Db_Abstract -> 资源模型
Mage_Core_Model_Resource_Db_Collection_Abstract -> 集合模型
好处是。 我现在可以向数据库添加新数据了。
但主要问题还是一样,没有显示网格。
我尝试在 magento 前端进行简单的数据检索,但它给了我致命错误:在非对象上调用成员函数 load()。
我还是 magento 的新手,我需要发现很多谜团。
型号
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');
}
}
这些是代码。
更新的 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>
更新:内容块
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));
}
}
问题:
没有网格只显示标题标题和添加按钮
单击添加按钮时,会显示表单,但我无法添加新项目
模型集合在 var 转储后返回“bool(false)”
问题:
你能帮我找出问题吗?
谢谢
【问题讨论】:
-
阅读内容太多,尤其是在我看到你几乎关注每一个细节之后......
-
@ElefantPhace 我道歉。
-
尝试在网格文件中打印集合是否有集合。转到 Block->Adminhtml->Pmadmin->Grid.php 保护函数 _prepareCollection() { $collection = Mage::getModel('pmadmin/pmadmin')->getCollection(); print_r($collection);死; $this->setCollection($collection);返回父级::_prepareCollection(); }
-
我已经尝试过了,但它没有显示任何内容。我还更新了我的模型,现在可以将新数据添加到数据库中。
-
您好 Rodge,我认为您的 config.xml 文件有问题按照给定教程链接的所有步骤操作。在您的 config.xml 中,使
和 应该与教程相同。我会建议你遵循与给定链接相同的副本。