In CakePHP 3.0, what's the difference between initialize () and beforeFilter ()?

I am moving from CakePHP 2.x, and I don’t understand what the difference is between initialize() and beforeFilter() . Between them, it seems, a lot of coincidences. When should I use one and not the other?

+6
source share
2 answers

This is the order in which events occur. initialize() is called immediately after the __construct() method, while beforeFilter() is called only when the action is beforeFilter() .

+5
source

initialize() always called.

beforeFilter() is optional. If present, it is:

called before the beforeFilter controller, but after the initialifiers () method.

http://book.cakephp.org/3.0/en/controllers/components.html#component-callbacks

+4
source

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


All Articles