Felix,
can you maybe show some of your code ? I'm still curious.
I have chosen a custom way but I don't claim to fully understand the
right way with cake's built-in functions.
Olivvv
Felix Geisendörfer wrote:
CakePHP does have a function for Models called "findAllThreaded", which
basically assumes your table has a field called parent_id and then
builds you a tree array based on that. It's really simple in usage and
works like a charm. I use it for some of my tree needs myself.
Hope that's useful,
Felix aka the_undefined
Olivier Percebois-Garve schrieb:
Yeah "outputting the tree" was a big design issue for me. I found no
perfect solution.
helpers are limited in the data you can pass to them. Components might
have been good
if I had higher OO skills. The guiListTree() method passes an array
that is recursively build,
so it requires a recursive function to transform into some HTML. I
don't like to have recursive logic
in a view file, to me it should stay super simple else I am quite
unable to read the code when there is
<?php ?> tags everywhere around.
I came to the conclusion that having a tree means :
-pump some data/wrap in some HTML/pump some data/wrap in some HTML/pump
some data/ ...etc
-as long as the recursion goes
In a MVC perspective it means that its code that is doing
MCV/MCV/MCV/MCV/MCV/... recursively.
AFAIK cake is doing MVC well but has no built-in way to repeat it
recursively.
In the end I choose to build my tree in the model. I added a
constructor so I could load the tree in a custom way.
This way I got a $this->Category->tree_array object that I could
access from anywhere I need. I added some
methods such as get_parent_node() get_root_node() get_childnodes() etc
in the model
Then I have $this->Category->get_root_node() etc accessible
anywhere.
After that I made a method in my controller that uses my new model
methods in order to output the tree.
I allowed to keep the code of the recursive method reasonably small
and readable. The only pitfall is to be unable
to use the html helper to build the HTML code, so I just made the
necessary strings myself.
One thing with that approach is that it loads the tree from the db only
once and put it in a var so there is no recursive queries on the
db, Something I really wanted to avoid because else the number of
queries can grow dramatically and get the site down.
That is my very personal approach, take it as it is, I'm no guru, I
just like to share and see other ways/opinions.
Olivvv
Pacifists wrote:
Olivier Percebois-Garve wrote:
Just out of curiosity what is your "meniutree" ?
I've implemented a (simple) tree management in my application,
and after having tried components and helpers I finally moved all my
methods to model,
which seems to me the most convenient way.
I don't think I fully understand how you've implemented this.
How do you output the tree then ? With some helper ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~----------~----~----~----~------~----~------~--~---
|