views:

209

answers:

4

I create table: id, name, thread_id The mainly thread has thread_id = 0, but their children has theard_id = id of parent, and how is the best and simplest solution to create list with children, and looks like:

  1. Category 1
    Product 1
    Product 2
  2. Category 2
    Product 3
    etc...

Maybe You have better solution for such a list?

Sorry, for my english:)

+1  A: 

I suspect that the easiest way may be to use Cake's own TreeBehavior. More on that at http://book.cakephp.org/view/91/Tree. I've never used it personally, but have heard good things. It should provide all of the tools (and instruction) you need.

Rob Wilkerson
I know this, and I used, but Tree Behavior is for unlimited levels, but, I want create the most simplest tree, only with 2 levels (parent and childrens). Tree behavior in this moment, will be "too big":)I know there is in CakePHP find('threaded'), but I can't understood this...
kicaj
Sounds like you might be after this: http://book.cakephp.org/view/812/find-threaded. I don't know the details, but it appears to use a hybrid of the nested set and adjacency list models.
Rob Wilkerson
+1  A: 

One of easiest and efficient is to use Tree behavior as proposed by kicaj-pl. But I suggest you to consider MultiTree Behavior. It's also using nested tree database model but allows you to create many trees with different root_id and independent left and right values (so update of one tree doesn't update any other).

radious
A: 

Ah! I found this sentence: When You use find('threaded') you have to field 'parent_id' for creating structure like tree... All works fine!

Thanks for replies, bye!

kicaj
A: 

Try the MPPT logic for It. For that you need 3 fields in your database table viz parent_id , lft , rght. And to implement it using CakePHP, CakePHP already provided the function for it for that please refer http://book.cakephp.org/view/228/Basic-Usage :)

Tushar Mahajan