我想创建一个用于 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/