问题:
我正在追踪一个问题,即我的模型上的getCollection()没有返回对象,但在运行以下代码时返回false:
var_dump(Mage::getResourceModel('referrer/transaction_collection'));
奇怪的是,它本地返回一个对象,而不是在部署的服务器上。
我尝试了什么:
我已经没有想法如何调试这个,有没有Magento陷阱我错过了?
我的代码:
引荐的/ etc / config.xml中
<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<TBP_Referrer>
<version>1.0</version>
</TBP_Referrer>
</modules>
<global>
<models>
<referrer>
<class>TBP_Referrer_Model</class>
<resourceModel>referrer_mysql4</resourceModel>
</referrer>
<referrer_mysql4>
<class>TBP_Referrer_Model_Mysql4</class>
<entities>
<transaction><table>referrer_transactions</table></transaction>
</entities>
</referrer_mysql4>
</models>
<resources>
<referrer_setup>
<setup>
<module>TBP_Referrer</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</referrer_setup>
<referrer_write>
<connection>
<use>core_write</use>
</connection>
</referrer_write>
<referrer_read>
<connection>
<use>core_read</use>
</connection>
</referrer_read>
</resources>
</global>
</config>
引荐/型号/ Transaction.php
class TBP_Referrer_Model_Transaction extends Mage_Core_Model_Abstract {
protected function _construct() {
$this->_init('referrer/transaction');
}
}
引荐/型号/ mysql4 / Transaction.php
class TBP_Referrer_Model_Mysql4_Transaction extends Mage_Core_Model_Mysql4_Abstract {
protected function _construct() {
$this->_init('referrer/transaction', 'transaction_id');
}
}
引荐/型号/ mysql4 /交易/ Collection.php
class TBP_Referrer_Model_Mysql4_Transaction_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract {
protected function _construct() {
$this->_init('referrer/transaction');
}
}
引荐/ SQL / referrer_setup /安装-1.0.php
$installer = $this;
$installer->startSetup();
$installer->run("
CREATE TABLE referrer_transactions(
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`referrer_id` int(11) DEFAULT NULL,
`percentage` int(11) DEFAULT '0',
`order_id` int(11) DEFAULT NULL,
`amount` decimal(11,2) DEFAULT NULL,
`timestamp` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `order_id` (`order_id`),
KEY `referrer_id` (`referrer_id`)
) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8;
");
$installer->endSetup();
答案 0 :(得分:1)
花了一段时间才找到它,我使用了错误的Abstract类。我正在使用:
Mage_Core_Model_Mysql4_Collection_Abstract
切换到以下解决了它:
Mage_Core_Model_Resource_Db_Collection_Abstract
答案 1 :(得分:1)
在我的情况下它是NULL,因为我忘了在/PROY/Test/Resource/Test/Colection.php中创建集合模型
<?php
class PROY_Test_Model_Resource_Test_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
public function _construct()
{
parent::_construct();
$this->_init('test/test');
}
}