Yii条件和params不工作

时间:2014-05-13 16:12:16

标签: php yii

我在CDbCriteria上遇到问题绑定参数, 下面的代码没有用

$criteria = new CDbCriteria;
$criteria->condition = "(arrival_date > ':start_date' and arrival_date < ':end_date')";
$criteria->params = array(":start_date" => $getStart, ":end_date" => $getEnd);

$admissionList = Admission::model()->findAll($criteria);

但是这个工作正常

$criteria = new CDbCriteria;
$criteria->condition = "(arrival_date > '$getStart' and arrival_date < '$getEnd')";

$admissionList = Admission::model()->findAll($criteria);

为什么?

2 个答案:

答案 0 :(得分:1)

试试这个

$criteria = new CDbCriteria;
$criteria->condition = "(arrival_date > :start_date and arrival_date < :end_date)";
$criteria->params = array(":start_date" => $getStart, ":end_date" => $getEnd);

$admissionList = Admission::model()->findAll($criteria);

享受:)

答案 1 :(得分:0)

试试这个,

 $admissionList=Admission::model()->findAll("arrival_data>:getStart AND arrival_data<:getEnd",array(":getStart"=>$getStart,":getEnd"=>$getEnd));