Magento:与单个管理模块中的多个数据库表进行交互 [英] Magento: Interacting with multiple database tables in single admin module

查看:38
本文介绍了Magento:与单个管理模块中的多个数据库表进行交互的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个从两个数据库表中获取数据的模块.此数据应显示在我的管理模块中.谁能为我提供一个有关此的教程?

I am working with a module that fetches data from two database tables. This data should appear in my admin module. Can anyone provide me with a tutorial for this ??

推荐答案

请按照以下步骤操作:

您必须在模块的adminhtml文件夹中找到以下方法.然后收集查询并执行如下联接:

You must locate following method in your adminhtml folder of module. and then collect the query and perform a join as follows :

protected function _prepareCollection() {
    $collection = Mage::getModel('modulename/modelname')->getCollection();
    $collection->getSelect()
                   ->join(/*perform a join here...*/ );
    $this->setCollection($collection);
    return parent::_prepareCollection();
}

此后,您可以根据返回的数据添加更多列.

After this youu can add more column based on the data eturned.

我希望您知道如何联接表,否则请发表评论,以便我为您提供示例.

I hope you know how to join a table, else please comment so i can provide you examples for it.

加入magento的示例

Example of join in magento

$collection = Mage::getModel('sales/order')->getCollection();
$collection->getSelect()->join( array('order_item'=> sales_flat_order_item), 'order_item.order_id = main_table.entity_id', array('order_item.sku'));

这篇关于Magento:与单个管理模块中的多个数据库表进行交互的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆