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 7819393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:55:53+00:00 2026-06-02T06:55:53+00:00

Using CakePHP 2.0 here. The title is a bit misleading, so to clear things

  • 0

Using CakePHP 2.0 here. The title is a bit misleading, so to clear things up – I have session array which is populated with ids of products as user adds them to cart. So this array goes like [0] => 25, [1] => 70 etc. Let’s say this array is called $products.

What I want to ask is is there some possibility to have array which I get by using ‘find’ model’s function (‘conditions’ => array(‘Product.id’ => $products)) to be sorted not by some of Model.field values (as in ‘order’ option), but by $products array indices, so that when I render the products content in view I would get all those products in cart sorted in such sequence as user were adding them.

Here’s an example –
Session array $products:

[0] => 35,
[1] => 15,
[2] => 25

Then I pass this array to conditions of find function:

$list = $this->Product->find('all', array('conditions' => array('Product.id' => $products)));

In the end $list gives me array which sorted by product.id. So instead of having:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 35 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 15 )),

[2] => Array
        (
            [Product] => Array
                (
                    [id] => 25 ))

I get:

[0] => Array
    (
        [Product] => Array
            (
                [id] => 15 )),
[1] => Array
        (
            [Product] => Array
                (
                    [id] => 25 )),
[2] => Array
        (
            [Product] => Array
                (
                    [id] => 35 ))

So far all the answers doesn’t solve my problem. Please, pay closer attention to the example I gave, it’s very simple, but the answers provided are in different key.

Again, I need final array $list to be sorted by indices of session array $products, but I get $list sorted by Product.id field, even though I didn’t specify any 'find(array('order'=> ...))' at all and even tried to set it to false.

  • 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-06-02T06:55:54+00:00Added an answer on June 2, 2026 at 6:55 am

    Don’t want to sound rude, but all of responses to my question were about how to order my array by Product id (which was clearly not what I asked) or suggestions on doing manual sql queries which is inappropriate. Seems like I couldn’t properly describe what I needed, but I tried to make it as clear as possible, sorry.

    I stumbled upon a solution while trying to find how to ‘disable order’ in cake. So basically what you need to do is to have an array (let’s call it $queue) where you keep product ids as they are added to cart, and then in ‘order’ option in find model function (or paginate) you should provide it like:

    'order'=>array('FIELD(Product.id,'.implode(',', $queue).')')
    

    $queue might look like this, as example:

    [queue] => Array
            (
                [0] => 51
                [1] => 1
                [2] => 11
            )
    

    In the end you get $list array in which the order of products is same as in $queue. If you didn’t specify ‘order’ then you would get you $list array like this:

     [queue] => Array
                (
                    [0] => 1
                    [1] => 11
                    [2] => 51
                )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using cakePHP 1.26. In the PostsController, I have this: $this->paginate=array('conditions'=>array('Reply.post_id'=>$id),'limit' => 1);
Im using cakephp 2.0 and i have data submitted that i want to cleanup,
I am using CakePHP framework with MySQL database and I have problem in saving
I'm using CakePHP but it's a question about the MVC pattern. I have in
I just started using CakePHP for a small project. I have rails experience, and
I am using CakePHP 2.0's integrated Auth component. I have the following tables :
I am trying to implement form validation using cakephp models. Here are my code
I am using cakePHP 1.26. I got an Input Text box which contains a
I am using Cakephp as my framework. I have a problem in uploading my
Using CakePHP 1.3.6 I'm sure I may have to add code and examples, but

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.