Access a model from a layout file in CakePHP

I am working on a CMS using CakePHP and want to create a dynamic menu that will be the same on all pages that the user can access. So I decided to create in the layout (since it was split between so many pages and the view), but I don't seem to know how to access the model and get data from the database to build the menu. any help is appreciated.

+3
source share
2 answers

This is because, in order to properly separate MVC * in Cake, you do not have to access the model from the view. The only part of accessing the data should be the Controller (via the Model), which transfers it to the View, which simply displays the data.

Thus, using the beforeFiltercallback globally AppControllerto set()probably the best choice.

In emergency situations, you can always access anything from anywhere by downloading an instance of the desired class using ClassRegistry::init, but you really have to "t.


* , " MVC" , . , , . Cake, Cake MVC, Cake - .

+16
+3

Source: https://habr.com/ru/post/1716990/


All Articles