tags:

views:

75

answers:

1

I'm trying to mimic a reddit feature. When you link to a specific comment in a threaded list (example), you can add a var 'context' in the url to show the context.
I can show you the comment I want you to see, plus a parent (context=1) or the parent's parent (context=2) and so on.

Now, cakePHP simplifies the threaded thing with find('threaded');, and I can link a comment and show a thread downside, but how can I make it upside, finding recursively parents n times?

Thanks, have an excelent 2010!

+1  A: 

Use TreeBehavior::getpath() for the comment you have the id for (does 2 queries).

Pop context items off the path array.

deizel
Right! Thanks! I was not using the Tree behaviour, I was just assigning a parent_id field.
metrobalderas
Cool, `TreeBehavior` is there to be used, but if you don't want to use MPTT, you can do it with recursive queries: Find the comment you have the `id` for. Find it's parent (`parent_id`), repeat `context` times. This will result in `context`+1 queries, instead of 2.
deizel