Wszystkie inne rozwiązania mają uzyskać nazwę kontrolera ... Potrzebuję samego kontrolera, więc zrobiłem następującą funkcję w AdminHelper.php wywołanym przez $this->Admin->_getController('MyControllerName')
w widoku.Plik CTP
/******************************************************************
*
******************************************************************/
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("Eval returned an error into ".__FILE__." getController()");
}
$controller->constructClasses();// If we want the model associations, components, etc to be loaded
$this->controllersArray[$pControllerName] = $controller;
}
$result = $this->controllersArray[$pControllerName];
return $result;
}
Uwaga: Nie zapomnij zgłosić go do sterownika będziesz używać na przykład:
- ludzie/view.ctp ->
$this->Admin->_getController('MyControllerName')
- PeopleController.ctp ->
var $helpers = array('Html', 'Form', 'Admin');
- AdminHelper.ctp ->
function _getController(...
Dzięki za podpowiedź o '$ this -params'! – Oberst