我希望能够使用 Yii 框架读取多行,而不必创建多个模型对象。考虑到这一点,我正在设置一个 CDbCriteria,其条件为 RowName = :param0 OR RowName = param1... RowName = ParamN 和相应的 params 值。
我的问题有两个。首先是 findall 失败。第二个是我不知道如何从 findall 调用中获取错误代码(因此返回“heartBeat”行)。
class Xactions extends CActiveRecord
{
.
.
.
//example $requests data: '192.168.1.162, 192.168.1.161'
//This function should return a Xactions model which is associated with any rows
// where tcpAddress = $requests Comma separated values.
public static function HeartBeatmodel($requests)
{
$criteria=new CDbCriteria;
$request_arr = explode(',', $requests);
$criteria->condition=Xactions::request_condition("tcpAddress", count($request_arr));;
$criteria->params= Xactions::request_params($request_arr);
$return= Xactions::model()->findall($criteria);
return "heartBeat"; // here for debugging purposes
}
public static function request_condition($column_name, $num_request){
//want to end up with name=:param1 OR name=:param2....
$return_str = "";
for ($i = 0; $i < $num_request; $i++){
$return_str .= $column_name . '=param' . (string)$i . ' ';
if($i == $num_request -1 ) break; //prevents extra OR statement
$return_str .= 'OR ';
}
return $return_str;
}
public static function request_params($requests){
$return_arr = array();
for ($i = 0; $i < count($requests); $i++){
$return_arr['param' . (string)$i] = $requests[$i];
}
return $return_arr;
}