phalcon: 目录分组后的acl权限控制

Posted 穆晟铭

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了phalcon: 目录分组后的acl权限控制相关的知识,希望对你有一定的参考价值。

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;
			
        });


    }

}

  

 

以上是关于phalcon: 目录分组后的acl权限控制的主要内容,如果未能解决你的问题,请参考以下文章

phalcon: eventManager事件管理(结合dispatcher调度控制器)制作简单的acl

Phalcon 持久型

CenTOS7使用ACL控制目录权限,只给某个用户访问特定目录

文件访问控制列表

Linux 访问控制acl

Phalcon PHP - 获取所有允许的资源