문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top