开发者

Dynamic Navigation Menu in CakePhp

开发者 https://www.devze.com 2023-04-02 10:43 出处:网络
I am working on a website where I have to use dynamic navigation menu on the sidebar. I have set variables in the beforeFilter() method in 开发者_运维问答AppController and using those variables, creat

I am working on a website where I have to use dynamic navigation menu on the sidebar.

I have set variables in the beforeFilter() 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.

Also it is not in accordance with the MVC pattern.

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,

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号