Dynamic Navigation Menu in CakePhp
I am working on a website where I have to use dynamic navigation menu on the sidebar.
I have set variables in thebeforeFilter()
method in 开发者_运维问答AppController
and using those variables, created an element for the sidebar.
I have 3 layouts and have used the element in all the 3 layouts.
I am not satisfied with this implementation as for every request the beforeFilter()
method in the AppController
has to be called.
Is there any better way to achieve this?
Usually, I would choose to let a Category model handle the retrieval of (sub)categories. You could then call the appropriate action from beforeRender (to prevent loading data while you never reach a point to render it) and, if necessary, pass the appropriate environmental values to your model.
On a sidenote, I usually apply the TreeBehaviour to the Category model. You've probably already done this but I couldn't make that up from your question.
Sincerely,
精彩评论