CakePHP function reachable from eveywhere

105 views Asked by At

Where in cake to create a function that will be able to be used by any controller, model, view and every other place. I know that this is not very OOP but I need a function for checking the mime_type of files. ATM I em using a variable set in the bootstrap but dont think that this is the best place because I dont need this on every page.

1

There are 1 answers

0
Sudhir Bastakoti On BEST ANSWER

CakePHP is object-oriented, thus you would be encouraged to create a class and a method inside it, not a bare function. To create a class you can use from anywhere, put a file in APP/libs (for example my_class.php), make a class in it (like "class MyClass"), and then import it wherever you want to use it (using "App::Import('Lib', 'MyClass');").

But as per your quesion, reachable from eveywhere, you could do it in any central file, such as config/bootstrap.php