Home  >  Article  >  Backend Development  >  Method to convert yii object result into array_PHP tutorial

Method to convert yii object result into array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:50:281653browse

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);  

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

www.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...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn