Method to convert Yii object results into arrays
When using Yii’s Active Record to obtain query results, the returned result set is an object type, but sometimes for For the convenience of data processing, the result set is expected to be in array form or JSON format. So what to do?
Convert yii object result to array
// 查找满足指定条件的结果中的第一行
$post=Post::model()->find($condition,$params);
// 查找具有指定主键值的那一行
$post=Post::model()->findByPk($postID,$condition,$params);
// 查找具有指定属性值的行
$post=Post::model()->findByAttributes($attributes,$condition,$params);
Copy after login
When returning a result, just use $post->attributes;. For conversion to an array, you can refer to the article on this site:
PHP object to array (Object to Array), Json to array (Json to Array) method
Articles you may be interested in
- Yii framework module development Analysis
- Understanding of Yiiapp() in Yii framework
- Detailed analysis and explanation of yii framework directory structure
- Yii controller action parameter binding processing
- Yii Summary of how to use database transactions
- Yii rules common verification rules memo
- How to configure the default controller and action in the yii framework
- Summary of operations related to adding, modifying, and deleting yii databases
http://www.bkjia.com/PHPjc/1017449.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1017449.htmlTechArticleThe method of converting the yii object result into an array uses Yii's Active Record to obtain the query results. Set is an object type, but sometimes for the convenience of data processing...