yii AR对象转换为数组


通过find findAll等查询出来的结果为CActiveRecord对象,有时候需要当做数组来处理

$testArObj = Test::model()->findAll();
$stuList = array();
if (!empty($testArObj)) {
    $stuList = json_decode(CJSON::encode($testArObj),true);
 }

// stuList现在就是数组  findAll查询结果返回空数组,find没有结果返回null

yii1中有时候会用到CActiveDataProvider对象和挂件widget来渲染末班,我们也可以把CActiveDataProvider对象转换为数组,方便调试。

// $this 就是当前的数据模型
$res = new CActiveDataProvider($this, array(
     'criteria'=>$criteria,
));
$stuList = json_decode(CJSON::encode($res->getData()),true);
print_r($stuList);die;
// ↑ stuList现在就是数组

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM