0

我想知道的是,如何将连接查询添加到 yii 搜索功能中。

搜索功能在货币模型中。(currency.php)

>public function search()
    {

        $criteria=new CDbCriteria;

        $criteria->compare('id',$this->id,true);
        $criteria->compare('name',$this->name,true);
        $criteria->compare('sign',$this->sign,true);

        return new CActiveDataProvider($this, array(
            'criteria'=>$criteria,
        ));
    }

我想将连接查询添加到该函数。我的查询是这样的:

SELECT * FROM currency cur INNER JOIN currency_option curopt ON cur.id = curopt.currency_id AND curopt.company_id = '$com_id'。

任何人请帮助我。非常感谢!

4

1 回答 1

2
$criteria=new CDbCriteria;
$criteria->join="INNER JOIN currency_option curopt ON cur.id = curopt.currency_id AND curopt.company_id = '$com_id'";
$criteria->compare('id',$this->id,true);
$criteria->compare('name',$this->name,true);
$criteria->compare('sign',$this->sign,true);

尝试这个。

于 2013-10-31T03:24:08.457 回答