2013-02-21 76 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