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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:01:12+00:00 2026-05-22T21:01:12+00:00

I have a cakephp app with a category model that acts as a Tree.

  • 0

I have a cakephp app with a category model that acts as a Tree. I imported ~100 categories through a csv file.

I want to be able to quickly reorder all the categories by name so that my index view is ordered correctly.

I tried the reorder method from the Tree behavior :

$this->Category->reorder(array(
'id' => null,
'field' => 'Category.name',
'order' => 'ASC'
));

But it doesn’t do anything. Am I missing something here ?

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-22T21:01:13+00:00Added an answer on May 22, 2026 at 9:01 pm

    I have just been looking into this and have come to the conclusion it is not possible to order the results in the generatetreelist() method – at least no easy way without looping through and manually moving each node. The best way to go about this is use the normal find method with the first argument as ‘threaded’, then you can apply SQL ordering like you would any query. I have this method in my Category model:

    public function getThreaded($conditions = array()) {
        return $this->find('threaded', array(
            'order' => 'Category.name ASC',
            'contain' => false
        ));
    }
    

    This returns me an array of all my parent categories alphabetically-ordered, with a ‘children’ key containing another array all the children of that category, in alphabetical order too! I use contain => false to cut down on the data returned (threaded returns data about each node’s parent, which we don’t need to know), you could alter it to include extra data if need be.

    I understand this isn’t 100% the same as generatetreelist(), but it’s certainly tidier and a lot more flexible as you control the output. If you really needed to emulate generatetreelist()‘s behavior, you could just loop through the array from above like so:

    $treeArray = array();
    foreach($category as $parent) {
        $treeArray[] = $parent['Category']['name'];
        if(!empty($parent['children']) {
            foreach($parent['children'] as $childCategory) {
                $treeArray[] = ' - '.$childCategory['Category']['name'];
            }
        }
    }
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my CakePHP 1.2.5 app, I have a Profile model that belongsTo a User
I have forms inside a cakephp app that load through ajax. These forms have
I have a CakePHP app that is being moved to Sql Server from MySql.
I have a simple cakephp app with table articles that has a cat_id column
I have a rather simple CakePHP app that uses the Auth component to restrict
I have a small cakePHP app that allows for user's to login and be
In my cakephp app I have an Option model. In my option/index view I
I have a Cakephp app that has users with ids and emails (emails might
I have a cakephp app that when I logout it add's admin/login ti the
I have built a CakePHP app that creates appointments which have both a client

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.