I was wondering where is the correct location to place the App::import on CakePHP2.
I was thinking that it should be better to use it in each function in order not to load if another function doesnt use it.
Something like this:
public function name(){
App::import('Controller', 'Classifiers');
$classifiersController = new ClassifiersController();
$this->request->data['Post'] = $classifiersController->getIdCategory('hola');
}
Instead of using the import at the top of the class.
What do you think?
the correct place for app::import: no where! 😉
you use App::uses() in 2.0 for all app classes (import is only for vendor stuff).
and you would place it at the very top of your file (after the
<?php)in your case:
although I HIGHLY recommend to take a closer look at what you are doing there.
using another controller in a controller is pretty wrong – in your case you would probably want to import a model and use its method. controllers are only for logic of a specific request action. place all other things in the model (fat model, slim controller principle).