0

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
user1018809
  • 211
  • 1
  • 3
  • 12
  • 4
    You want the function to be used by "any controller, model, view and every other place", but bootstrap.php isn't good because you "don't need this on every page"? Which is it? – JJJ Jan 23 '12 at 09:25
  • Agree with the comment above. Perhapse create a php file with your function, put it in the vendors dir, then import when you need it using App::import – Scott Harwell Jan 23 '12 at 13:36

1 Answers1

3

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

Sudhir Bastakoti
  • 99,167
  • 15
  • 158
  • 162