How to convert Yii object results to arrays _php Tutorial

Source: Internet
Author: User

Methods for converting Yii object results to arrays


When using the active Record of yii to get the result of the query, the result set returned is an object type, but sometimes it is convenient for data processing that the result set is in array form or JSON format. What should we do then?

To convert a Yii object result to an array

Finds the first row in the results that meet the specified criteria  $post =post::model ()->find ($condition, $params);  Finds the row with the specified primary key value  $post =post::model ()->findbypk ($postID, $condition, $params);  Finds the row with the specified attribute value  $post =post::model ()->findbyattributes ($attributes, $condition, $params);  

When returning a result, use the $post directly->attributes; You can do it. To convert to an array, you can refer to this site article:

PHP Object goto Array (object to array), JSON to array (JSON to array) method

Articles you may be interested in

    • Analysis of module development of YII Framework Framework
    • The understanding of Yii Framework Yiiapp ()
    • Yii Framework directory structure detailed analysis description
    • The action parameter binding processing of YII controller
    • Summary of usage methods of database transactions in Yii
    • YII rules common validation Rule memo
    • How the YII framework configures the default controller and action
    • Yii database Add, modify, delete related Operations summary

http://www.bkjia.com/PHPjc/1017449.html www.bkjia.com true http://www.bkjia.com/PHPjc/1017449.html techarticle when the result of a Yii object is converted to an array using Yii's active Record to get query results, the returned result set is an object type, but sometimes it is convenient for data processing ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.