Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put custom global functions in CakePHP?

Tags:

php

cakephp

I want to add implementation of array_column() for CakePHP app that is currently running on PHP 5.3 (array_column() has been introduced in PHP 5.5). What would be the best method of doing it without touching core files?

Please note that I don't want to use helper, I really want to define global function.

like image 848
matt Avatar asked Mar 10 '15 19:03

matt


1 Answers

If you don't want to write a helper there are a few places where you can put global functions. If you're going to use the functions only in your controllers the best place is the AppController. In a similar way you could use the AppModel class for model functions and for the views you could put them within a layout.

But if you want to use the functions across the entire application, I would recommend putting them inside the app/Config/bootstrap.php file.

like image 163
Pablo Flores Avatar answered Nov 09 '22 22:11

Pablo Flores