1. 程式人生 > >phalcon: 目錄分組後的acl權限控制

phalcon: 目錄分組後的acl權限控制

gist gic ade efi mixed dump html face AD

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