无论如何都可以更改查询的结果,我的数据库表中有几列带有 1 和 0 值,但是 1 和 0 都有含义,比方说 1=可以跳转 0=不跳转,
我使用下面的代码进行查询,它会给我返回带有 0 和 1 的列,无论如何都很容易将此值更改为可以跳转/不跳转,我猜想像过滤器或其他东西....
public function search()
{
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('id',$this->id,true);
$criteria->compare('result',$this->result,true);
$criteria->compare('p_city',$this->p_city,true);
$criteria->compare('p_state',$this->p_state,true);
$criteria->compare('d_city',$this->d_city,true);
$criteria->compare('d_state',$this->d_state,true);
$criteria->compare('type',$this->type,true);
$criteria->compare('date_search',$this->date_search,true);
$criteria->compare('date_shipped',$this->date_shipped,true);
$criteria->compare('driveable',$this->driveable,true);
$criteria->compare('enclosing',$this->enclosing,true);
$criteria->compare('type_service',$this->type_service,true);
$criteria->order='date_search desc';
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
最佳答案
您可以通过在模型中使用 afterFind
函数来完成此操作:
public function afterFind() {
$this->driveable == '1' ? 'Yes' : 'No';
}
关于mysql - 改变查询结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21950551/