Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6575689
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:25:07+00:00 2026-05-25T15:25:07+00:00

I am using a CDbCriteria with its own conditions, with & order clauses. However,

  • 0

I am using a CDbCriteria with its own conditions, with & order clauses. However, the order i want to give to the elements in the array is way too complex to specify in the order clause.

The solution i have in mind consists of obtaining the active records with the defined criteria like this

$theModelsINeed = MyModel::model()->findAll($criteria); 

and then rearrange the order from my php code. How can i do this? I mean, i know how to iterate through its elements, but i don´t know if it is possible to actually change them.

I have been looking into this link about populating active records, but it seems quite complicated and maybe someone could have some better advice.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T15:25:07+00:00Added an answer on May 25, 2026 at 3:25 pm

    There is nothing special about Yii’s active records. The find family of methods will return an array of objects, and you can sort this array like any other array in PHP.

    If you have complex sort criteria, this means that probably the best tool for this is usort. Since you will be dealing with objects, your user-defined comparison functions will look something like this:

    function compare($x, $y)
    {
        // First sort criterion: $obj->Name
        if ($x->Name != $y->Name) {
            return $x->Name < $y->Name ? -1 : 1; // this is an ascending sort
        }
    
        // Second sort criterion: $obj->Age
        if ($x->Age != $y->Age) {
            return $x->Age < $y->Age ? 1 : -1; // this is a descending sort
        }
    
        // Add more criteria here
    
        return 0; // if we get this far, the items are equal
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Nunit, I want to be able to write a test fixture that will
Using WPF/PRISM I want to log my messages through ILoggerFacade to my GUI (A
I am trying to use bitwise operations when quering the DB using a CDbCriteria
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and
Using emacs on Ubuntu 11.10. I want to connect to a SQL Server database
I am trying to do a Join query using CDBCriteria in Yii framework. The
I'm wondering how can I find these records using the CActiveRecord / CDbCriteria in
Using restlet, I want to make a post to android's c2dm service. I have
Using online interfaces to a version control system is a nice way to have
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.