This is what I did, the basic idea is,
- use a plugin to set modules, controller, and action.
- then verify modules, controller and action to see if it is a private resources.
<?php
namespace Multiple\Plugins\Common;
use Phalcon\Events\Event;
use Phalcon\Mvc\User\Plugin;
use Phalcon\Mvc\Dispatcher;
class AclListener extends Plugin
{
protected $_module;
public function __construct($module)
{
$this->_module = $module;
}
public function beforeDispatch(Event $event, Dispatcher $dispatcher)
{
$moduleName = $this->_module;
$controllerName = $dispatcher->getControllerName();
$actionName = $dispatcher->getActionName();
if ($this->acl->isPrivate($moduleName, $controllerName, $actionName)){
var_dump('need verify');
}
}
}
Then in Acl class
<?php
namespace Multiple\Acl;
use Phalcon\Mvc\User\Component;
class Acl extends Component
{
private $privateResources = array(
'frontend'=>array(
'users'=>array(
'index',
),
'products'=>array(
),
),
'backend'=> array()
);
public function isPrivate($module, $controller, $action)
{
$pr = $this->privateResources;
if(isset($pr[$module]) and empty($pr[$module]))
{
return true;
}else if(isset($pr[$module][$controller]) and empty($pr[$module][$controller]))
{
return true;
}else if(in_array($action, $pr[$module][$controller]))
{
return true;
}
return false;
}
}