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

  • Home
  • SEARCH
  • 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 8826717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:12:31+00:00 2026-06-14T07:12:31+00:00

Using the example in the Cookbook: http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html If you debug() this you get a

  • 0

Using the example in the Cookbook:
http://book.cakephp.org/2.0/en/core-libraries/behaviors/tree.html

If you debug() this you get a flat array() of category(id => name)

Which is fine for most purposes, but if you wanted to create navigation based on this and had a slug for the URL, rather than the id, you’re out of luck.

I’m aware that I could use $this->Category->find(‘threaded’) in the controller to get all fields but it lacks the convenience of the flat list because I have to create a recursive function to generate the links using the slug, exactly what I’d hoped to avoid.

So what’s the best way to get the additional Category.slug field I need in the view?

  • 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-14T07:12:32+00:00Added an answer on June 14, 2026 at 7:12 am

    CakePHP’s generateTreeList() method allows you to choose the keys and values that are returned. If, for example, you wished to return a list that had the slug as the key and the link text as the value, you could use the $keyPath and $valuePath parameters to make it so:

    $data = $this->Category->generateTreeList(null, "{n}.Category.slug", "{n}.Category.text", '_');
    debug($data); die;
    

    might produce:

    array(
        ["my-categories"] =>  "My Categories",
        ["fun"] =>  "_Fun",
        ["sport"] =>  "__Sport",
        ["surfing"] =>  "___Surfing",
        ["skating"] => "___Skating",
        ["friends"] =>  "__Friends",
        ["gerald"] =>  "___Gerald",
        ["gwendolyn"] =>  "___Gwendolyn",
        ["work"] =>  "_Work",
        ["trips"] => "__Trips",
        ["national"] => "___National",
        ["international"] => "___International",
        ["other-peoples-categories"] => "Other People's Categories",
        ["extreme-fishing"] =>  "_Extreme fishing"
    )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to work out how to load a module using example http://dojotoolkit.org/reference-guide/dojo/registerModulePath.html I
I am doing something very similar to this cookbook example http://symfony.com/doc/current/cookbook/form/dynamic_form_generation.html#adding-an-event-subscriber-to-a-form-class The main difference
I'm using the example found here: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01 The issue is that when I specify
Reading PHP & jQuery Cookbook right now and it gives this example for using
Using the example at the following URL: http://www.kavoir.com/2009/02/php-drop-down-list.html How can I have that drop
Try to use the FEST-Swing for Swing GUI testing, and using example from http://easytesting.org/swing/wiki/pmwiki.php?n=FEST-Swing.LaunchFromMain
I have looked at this example using php and GD to piecewise-render a spiral
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
I saw this C# using statement in a code example: using StringFormat=System.Drawing.StringFormat; What's that
i have to create a program to login on facebook using example http://code.google.com/p/facebook-java-api/wiki/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.