访问Magento自定义模块中2个表中的数据
我需要一些帮助。我在magento中创建了一个需要与多个表交互的自定义模块 我使用了以下方法来获取表名访问Magento自定义模块中2个表中的数据,magento,model,Magento,Model,我需要一些帮助。我在magento中创建了一个需要与多个表交互的自定义模块 我使用了以下方法来获取表名 <entities> <support1> <table>table1</table> </support1> <support2> <table>table2</table> </support2>
<entities>
<support1>
<table>table1</table>
</support1>
<support2>
<table>table2</table>
</support2>
<support3>
<table>table3</table>
</support3>
</entities>
在mysql4文件夹中,我有
public function _construct()
{
$this->_init('support/support1', 'ticket_id');
$this->_init('support/support2', 'dept_id');
$this->_init('support/support3', 'priority_id');
}
public function _construct()
{
parent::_construct();
$this->_init('support/support1');
$this->_init('support/support2');
$this->_init('support/support3');
}
在Collection.php中我有
public function _construct()
{
$this->_init('support/support1', 'ticket_id');
$this->_init('support/support2', 'dept_id');
$this->_init('support/support3', 'priority_id');
}
public function _construct()
{
parent::_construct();
$this->_init('support/support1');
$this->_init('support/support2');
$this->_init('support/support3');
}
所以使用
$collection = Mage::getModel('support/support')->getCollection();
如何定义对support1或support2等的访问权限。我已尝试使用
$collection = Mage::getModel('support/support1')->getCollection();
及
但两次都失败了,这应该怎么办
提前感谢。尝试创建以下文件夹结构,并根据需要更新每个文件的类定义
|-/Model
|---Support1.php
|---Support2.php
|---Support3.php
|------Mysql4
|--------Support1.php
|--------Support1
|----------Collection.php
|--------Support2.php
|--------Support2
|----------Collection.php
|--------Support3.php
|--------Support3
|----------Collection.php
class <CompanyName>_<ModuelName>_Model_Support[x] extends Mage_Core_Model_Abstract
class <CompanyName>_<ModuelName>_Model_Mysql4_Support[x] extends Mage_Core_Model_Mysql4_Abstract
class <CompanyName>_<ModuelName>_Model_Mysql4_Support[x]_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract
|-/Model
|---Support1.php
|---Support2.php
|---Support3.php
|------Mysql4
|--------Support1.php
|--------支持1
|----------Collection.php
|--------Support2.php
|--------支持2
|----------Collection.php
|--------Support3.php
|--------支持3
|----------Collection.php
类模型支持[x]扩展了Mage核心模型抽象
类_模型_Mysql4_支持[x]扩展了Mage_核心_模型_Mysql4_抽象
类\模型\ Mysql4\支持[x]\集合扩展了Mage\核心\模型\ Mysql4\集合\抽象
Magento没有“一个模块,一个数据类”的结构。相反,单个模块可能包含许多不同的型号。每个模型类访问一个表
因此,您的代码生成工具为您提供了三个类
Package_Support_Model_Support //model
Package_Support_Model_Resource_Mysql4_Support //model resource
Package_Support_Model_Resource_Mysql4_Support_Collection //collection
这三个类构成了Magento中的单个模型
因此,如果您想要support1,您还需要另外三个类
Package_Support_Model_Support1 //model
Package_Support_Model_Resource_Mysql4_Support1 //model resource
Package_Support_Model_Resource_Mysql4_Support_Collection1 //collection
这将使
Mage::getModel('support/support1');
上述代码示例从名为support1的支持模块中获取模型
具体细节对于单个StackOverflow答案来说太多了,但是如果您需要更多帮助,这就包括在没有代码创建工具的情况下从头开始创建模型 Alan,谢谢你的回复,这是你的教程,我用来建立我的扩展,所以非常感谢你,这是非常有益的信息和帮助。上面的答案是正确的,但是我给你的文章加了一个加号,因为它对我帮助很大。应该是
Mage::getModel('support/support1')代码>(双冒号)