2013-02-21 16 views
0

是否有人知道如何在yii中使用andWhere()條件。當我使用它時,出現以下錯誤。如何在Yii中使用和在哪裏

CDbCommand and its behaviors do not have a method or closure named "andWhere". 

這裏是示例代碼

$result=Yii::app()->db->createCommand() 
->select() 
->from('{{product}}') 
->andWhere('price>:param1', array(':param1'=>150)) 
->andWhere('price<:param2', array(':param2'=>210)) 
->queryAll(); 
+0

你可以在你想要使用它的地方添加代碼片段嗎? – cdmckay 2013-02-21 14:13:57

+0

是的,我添加了一些示例代碼 – 2013-02-21 14:18:29

回答

6

在yii 1.1.13中添加了andWhere()函數。看來你使用的是舊版本的yii。更新框架

+0

如何更新它,我目前使用1.1.10 – 2013-02-21 14:28:14

+0

從http://yiiframework.com/下載最新版本並更新。根據http://static.yiiframework.com/files/UPGRADE-1.1.13.txt更改您的代碼 – dInGd0nG 2013-02-21 14:30:55

-1

怎麼樣嘗試這種方法,這是一個很容易peazy

Yii::app()->db->createCommand() 
     ->select("*") 
     ->from('package') 
     ->where('id=:id and status:status', array(':id'=>5,':status'=>1)) 
     ->queryRow(); 

甚至

$criteria = new CDbCriteria(); 
    $criteria->condition = 'id=:id and status=:status'; 
    $criteria->params = array(':id'=>$id,':status'=>1); 

確切

$result=Yii::app()->db->createCommand() 
    ->select() 
    ->from('{{product}}') 
    ->where('price>:param1 and price<:param2', array(':param1'=>150,':param2'=>210)) 
    ->queryAll(); 
+0

在複製和粘貼之間的某個時間點,您應該已經意識到此代碼與OP要求的內容無關。 – Jon 2013-02-21 14:23:43

+0

我是givin的例子兄弟! – 2013-02-21 14:32:11

+0

*無關*例子。 – Jon 2013-02-21 14:33:52

相關問題