简体   繁体   中英

In CakePHP 3.0 what is the difference between initialize() and beforeFilter()?

I'm transitioning from CakePHP 2.x and it's not clear to me what the difference is between initialize() and beforeFilter() . There seems to be a lot of overlap between them. When should I use one and not the other?

It is the order in which the events happen. initialize() is called right after the __construct() method, whereas beforeFilter() is only called if an action is dispatched.

initialize() is always called.

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

called before the controller's beforeFilter method, but after the controller's initialize() method.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM