Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 548
emersonthis Avatar asked Apr 21 '15 18:04

emersonthis


People also ask

What is beforeFilter in CakePHP?

beforeFilter() executes functions that you NEED to be executed before any other action. Controller::beforeFilter() This function is executed before every action in the controller. It's a handy place to check for an active session or inspect user permissions. http://api.cakephp.org/2.3/class-Controller.html#_ ...

What is Component in CakePHP 3?

Components are packages of logic that are shared between controllers. CakePHP comes with a fantastic set of core components you can use to aid in various common tasks. You can also create your own components.

What is components in CakePHP?

A CakePHP component A component is a class file which contains the common code or logic. The component can be shared between the application's controllers. CakePHP comes with some good components, so you can perform various common tasks like session handling, cookies and security related things, etc.


1 Answers

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.

like image 167
José Lorenzo Rodríguez Avatar answered Nov 07 '22 14:11

José Lorenzo Rodríguez