I'm working with Cake 2.2.4. I've learned perhaps more than I ever cared to about nested sets and really appreciate how well Cake manages them. Unfortunately, for all my research, I haven't been able to find a way to create an array from my Category model that will give the full path for each Category. Since, in my system, very different categories can have the same name, the path (coupled with the ID for the category) is essential. I think it comes across best in an illustration. Suppose my table looked like this (without the lft, rght, and parent_id fields that are in the actual table):
ID Category
1 CakePHP
2 Overview
3 Controllers
4 AppController
5 User Management
6 Overview
7 Profiles
8 CSS3
9 Overview
10 Forms
11 Canvas
12 Animation
I'd like to be able to generate an array that looks like this:
1 CakePHP
2 CakePHP > Overview
3 CakePHP > Controllers
4 CakePHP > Controllers > AppController
5 CakePHP > User Management
6 CakePHP > User Management > Overview
7 CakePHP > User Management > Profiles
8 CSS3
9 CSS3 > Overview
10 CSS3 > Forms
11 CSS3 > Canvas
12 CSS3 > Canvas > Animation
As you can see, just listing the category name, such as "Overview," can be totally confusing. You need the path to make it intelligible. generateTreeList() works great to generate a dropdown list, but if I need to display the categories associated with a specific topic, it's not useful at all; I need to display those as a single item for each topic like I illustrate above. I've messed around with getPath() but the documentation on it is scanty to say the least, and I can't seem to find any illustrations of its use. In any case, it doesn't look getPath() will do what I want.
I suppose I could just create the categories as complete paths and avoid the whole nested set issue altogether, but that kind of defeats the purpose of having a dynamic database system.
Any help or ideas would be greatly appreciated. I can't imagine why this hasn't been dealt with in a plugin or behavior before. It seems to be a fairly common use. In many ways, it's like breadcrumbs but dealing with a series of records rather and single item.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to cake-php+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
Tuesday, December 4, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment