Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Controller inheritance in Cake PHP?

Has anyone attempted this? Is it possible, and if so, what kind of problems will I run into if I try to accomplish it?

like image 746
matt_dev Avatar asked Jul 15 '26 17:07

matt_dev


1 Answers

If you goal is to share logic between controllers:

  • add the logic to the AppController to share it with all the controllers in your app.

  • make a component and add that to $this->components for the controllers you want to share it.

Adding additional inheritance between controllers should only be concidered as a last resort, as you have to pay extra attention to how components and helpers are handled. E.g. you must manually merge $this->components & $this->helpers with the AppController and the controller you are inheriting from.

like image 179
Ronny Vindenes Avatar answered Jul 18 '26 07:07

Ronny Vindenes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!