|
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: --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php -~----------~----~----~----~------~----~------~--~--- |
- Re: A way to have global component Pacifists
- Re: A way to have global component Pacifists
- Re: A way to have global component Olivier Percebois-Garve
- Re: A way to have global component Felix Geisendörfer
- Re: A way to have global component Olivier Percebois-Garve
- Re: A way to have global component Olivier Percebois-Garve
