phalcon: 目录分组后的acl权限控制
楼主在做acl权限的时候,发现官方的acl只能针对未分组的目录,如下:
app/ ___|./controller ___|./logic ___|./plugins ___|./models ..............
但是对分组不支持,后来想想,是支持的.分组的目录如下
app/ ___|./admin/ __________|./controllers __________|./logic __________|./views __________|./module.php ___|./home/ __________|./controllers __________|./logic __________|./views __________|./module.php .........................................
那么可以将,如下代码,直接加入到,分组目录下的 module.php代码中
$di[‘aclResource‘]=function(){
return include_once ‘../app/configs/frontAcl.php‘;
};
$di[‘dispatcher‘] = function(){
$eventManager = new \Phalcon\Events\Manager();
$securyDeep = new \SecurityDeep();
$eventManager->attach("dispatch", $securyDeep);
$dispatch = new \Phalcon\Mvc\Dispatcher();
$dispatch->setEventsManager($eventManager);
return $dispatch;
};
全代码:
use Phalcon\Loader,
Phalcon\Mvc\Url,
Phalcon\Mvc\Dispatcher,
Phalcon\DiInterface,
Phalcon\Mvc\ModuleDefinitionInterface,
Phalcon\DI\Injectable,
Phalcon\Mvc\Router;
class Module extends Injectable implements ModuleDefinitionInterface
{
/**
* Registers the module auto-loader
*/
public function registerAutoloaders(DiInterface $dependencyInjector = null)
{
$loader = new Loader();
$loader->registerNamespaces(array(
‘App\Home\Controllers‘ => __DIR__ .‘/controllers/‘
))->register();
$loader->registerDirs(
array(
‘modelsDir‘ => ‘../app/models/‘,
‘pluginsDir‘ => ‘../app/plugins/‘,
)
)->register();
}
/**
* Registers the module-only services
*
* @param DiInterface $di
*/
public function registerServices(DiInterface $di)
{
$di[‘aclResource‘]=function(){
return include_once ‘../app/configs/frontAcl.php‘;
};
$di[‘dispatcher‘] = function(){
$eventManager = new \Phalcon\Events\Manager();
$securyDeep = new \SecurityDeep();
$eventManager->attach("dispatch", $securyDeep);
$dispatch = new \Phalcon\Mvc\Dispatcher();
$dispatch->setEventsManager($eventManager);
return $dispatch;
};
/**
* @return mixed
*/
$di[‘baseUrl‘] = function () {
$url = new Url();
$url->setBaseUri(‘/‘);
return $url;
};
/**
* 设置view
*/
$di->set(‘view‘, function () use($di) {
$view = new \Phalcon\Mvc\View();
//var_dump($di[‘modules‘][‘home‘][‘viewsDir‘]);exit;
$view->setViewsDir(BASE_PATH . $di[‘modules‘][‘home‘][‘viewsDir‘]);
$view->registerEngines(array(
‘.phtml‘ => ‘Phalcon\Mvc\View\Engine\Php‘
));
return $view;
});
}
}
原文:https://www.cnblogs.com/achengmu/p/9044431.html