I needed to select a controller in CakePHP 2.4 and display all the functions written in it. I found how to list controllers from this question & answer thread on Stack Overflow but what I need now is given a specific controller I need to get the list of all functions it contains.
Here what i have done
public function getControllerList() {
$controllerClasses = App::objects('controller');
pr($controllerClasses);
foreach($controllerClasses as $controller) {
$actions = get_class_methods($controller);
echo '<br/>';echo '<br/>';
pr($actions);
}
}
pr($controllerClasses); gives me list of controllers as follows
Array
(
[0] => AppController
[1] => BoardsController
[2] => TeamsController
[3] => TypesController
[4] => UsersController
)
however pr($actions); nothing... :(
here you go the final working snippet the way i needed
http://www.cleverweb.nl/cakephp/list-all-controllers-in-cakephp-2/
public function getControllerList() {
$controllerClasses = App::objects('controller');
foreach ($controllerClasses as $controller) {
if ($controller != 'AppController') {
// Load the controller
App::import('Controller', str_replace('Controller', '', $controller));
// Load its methods / actions
$actionMethods = get_class_methods($controller);
foreach ($actionMethods as $key => $method) {
if ($method{0} == '_') {
unset($actionMethods[$key]);
}
}
// Load the ApplicationController (if there is one)
App::import('Controller', 'AppController');
$parentActions = get_class_methods('AppController');
$controllers[$controller] = array_diff($actionMethods, $parentActions);
}
}
return $controllers;
}