动态 ACL 检查
创建一个 Security 类来运行 ACL 逻辑。
<?php
namespace Plugins;
use Phalcon\Events\Event;
use Phalcon\Mvc\Dispatcher;
use Phalcon\Acl;
use Phalcon\Acl\Role;
use Phalcon\Acl\Resource;
use Phalcon\Acl\Adapter\Memory as AclList;
class Security extends \Phalcon\Mvc\User\Plugin
{
public function beforeExecuteRoute(Event $event, Dispatcher $dispatcher)
{
// your acl logic here
}
}
将 Security 类挂钩到调度程序,以在 beforeExecuteRoute 上运行。
$di = new \Phalcon\DI\FactoryDefault();
$eventsManager = $di['eventsManager'];
$di->setShared('dispatcher', function() use ($eventsManager) {
$eventsManager->attach('dispatch:beforeExecuteRoute', new \Plugins\Security);
$dispatcher = new \Phalcon\Mvc\Dispatcher;
$dispatcher->setEventsManager($eventsManager);
return $dispatcher;
});