Yii SQL 到 CActiveDataProvider
我需要 Yii 专家的帮助,我有一个 SQL 查询,
SELECT p.name , p.price FROM products as p, prod_cat as pc WHERE pc.id_pr = p.id_pr AND pc.id_cat in (SELECT id_cat FROM prod_cat where id_pr=<myid>)
我需要将其转换为 Yii 中的 CActiveDataProvider。像这样
$dataProvider2=new CActiveDataProvider('Products',array(
'criteria' => array(
...
),
));
我有3个表:产品、类别和Prod_cat(其他两个表之间的连接)。 我需要从我提供的同一类别的商品中找到其他产品 ()。
I need help from Yii experts, I have a SQL query
SELECT p.name , p.price FROM products as p, prod_cat as pc WHERE pc.id_pr = p.id_pr AND pc.id_cat in (SELECT id_cat FROM prod_cat where id_pr=<myid>)
I need to convert this to CActiveDataProvider in Yii. something like this
$dataProvider2=new CActiveDataProvider('Products',array(
'criteria' => array(
...
),
));
I have 3 Tables : Products, Categories and Prod_cat (connection between two others).
I need to find others products from the same category of item that i provide ().
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将在您的数据库中创建一个视图(使用该查询)。然后根据该视图在 Yii 中制作一个模型。创建一个 activedataprovider 将变得很容易。
http://en.wikipedia.org/wiki/View_(database)
I would create a view in your database (using that query). Then make a model in Yii based on that view. Creating an activedataprovider will then be easy.
http://en.wikipedia.org/wiki/View_(database)
一个想法是使用具有关系的模型。
http://www.yiiframework.com/doc/guide/1.1/en /database.arr
另一种方式是使用DAO,但它不适用于CActiveDataProvider
One Idea is to use an model with relations.
http://www.yiiframework.com/doc/guide/1.1/en/database.arr
The other way is to use DAO, but it does not work with CActiveDataProvider