dongzhao3040 2011-05-16 13:10
浏览 42
已采纳

Yii SQL到CActiveDataProvider

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 ().

  • 写回答

2条回答 默认 最新

  • duanbei8904 2011-05-16 18:01
    关注

    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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?