我想知道的是,如何将连接查询添加到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,
));
}
我想将连接查询添加到该函数。 Myquery就是这样:
SELECT * 来自货币 INNER JOIN currency_option curopt ON cur.id = curopt.currency_id AND curopt.company_id ='$ com_id'。
任何人都请帮助我。非常感谢!
答案 0 :(得分:1)
$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);
试试这个。