如何在zend框架中列出所有控制器和操作

时间:2010-11-23 09:19:07

标签: php zend-framework

如何以编程方式列出每个模块的所有模块以及所有控制器和操作?

感谢

1 个答案:

答案 0 :(得分:3)

   $front = $this->getFrontController();
    $acl = array();

    foreach ($front->getControllerDirectory() as $module => $path) {

            foreach (scandir($path) as $file) {

                    if (strstr($file, "Controller.php") !== false) {

                            include_once $path . DIRECTORY_SEPARATOR . $file;

                            foreach (get_declared_classes() as $class) {

                                    if (is_subclass_of($class, 'Zend_Controller_Action')) {

                                            $controller = strtolower(substr($class, 0, strpos($class, "Controller")));
                                            $actions = array();

                                            foreach (get_class_methods($class) as $action) {

                                                    if (strstr($action, "Action") !== false) {
                                                            $actions[] = $action;
                                                    }
                                            }
                                    }
                            }

                            $acl[$module][$controller] = $actions;
                    }
            }
    }