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?
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$keyPathand$valuePathparameters to make it so:might produce: