In a controller, what is the most appropriate way to call the action of another controller and also pass an array as parameter?
I know that you can use requestAction
I put into my AppController class the following method and variable so it is caches in case of multiple calls
var $controllersArray = array();
function _getController( $pControllerName ){
if ( ! isset($this->controllersArray[$pControllerName]) ){
$importRes = App::import('Controller', $pControllerName);// The same as require('controllers/users_controller.php');
$strToEval = "\$controller = new ".$pControllerName."Controller;";
$evalRes = eval($strToEval);
if ( $evalRes === false ){
throw new AppException("Error during eval of given getController '$pControllerName'");
}
$controller->constructClasses();// If we want the model associations, components, etc to be loaded
$this->controllersArray[$pControllerName] = $controller;
}
$result = $this->controllersArray[$pControllerName];
return $result;
}