php - 从 Zend Framework 应用程序获取所有模块、 Controller 和操作

标签 php zend-framework

我想创建一个用于 ACL 管理的 Zend Controller ,所以我的问题是:如何获取 Zend 应用程序中的所有模块名称、控件名称和操作名称以构建 ACL 控件?

我使用 Zend_Navigation,如果您的 ACL 中不存在该资源,则 Zend_Navigation 会抛出异常。我想使用数据库来拒绝和允许访问。所以我必须先建立数据库。如果我必须手动执行此操作,那会很痛苦。

最佳答案

这可能是一个老问题,但这就是我这样做的方式......

//        $front = Zend_Controller_Front::getInstance(); // use this line instead on a model class
    $front = $this->getFrontController(); // this in controller
    $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;
                $class = substr($file,0,strpos($file,".php"));

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

                    $controller = strtolower(substr($file, 0, strpos($file, "Controller")));
                    $methods = array();

                    foreach (get_class_methods($class) as $method) {
                        if (strstr($method,"Action") != false) {
                            array_push($methods,substr($method,0,strpos($method,"Action")));
                        }
                    }
                }

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

关于php - 从 Zend Framework 应用程序获取所有模块、 Controller 和操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/887947/

相关文章:

PHP mySQL 查询后对结果进行排序

php - Zend framework 2/Doctrine 2/批量操作和事件触发

zend-framework - 基于 session 的表 zend 框架

php - 设置 Zend Soap 客户端内容类型

php - ZF2 Zend Registry 的替代品

php - 如何根据数据库中的值制作/生成图形图像?

php - 我数据库中的 "UTF8"数据真的编码正确吗?

php - 增加文件上传大小 Wordpress/IIS 7

php - 通用编程 : How to implement model logic in MVC?

php mysql 获取带有字符问题的名称