码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2018-05-16 11:03:24      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:efi   inject   AC   sha   att   phalcon   ret   Once   set   

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权限控制

标签:efi   inject   AC   sha   att   phalcon   ret   Once   set   

原文地址:https://www.cnblogs.com/achengmu/p/9044431.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!