我对 phalcon 的 acl 有一点错误。我有 beforeExecuteRoute 功能,它允许或拒绝具有角色的用户访问特定的控制器/操作。
public function beforeExecuteRoute (Event $event, Dispatcher $dispatcher) {
$role = $this->session->get('role');
if (!$role) {
$role = self::GUEST;
}
//Get the current controller and action from the dispatcher
$controller = $dispatcher->getControllerName();
$action = $dispatcher->getActionName();
//Get the ACL rule list
$acl = $this->_getAcl();
//See if they have permission
$allowed = $acl->isAllowed($role, $controller, $action);
if ($allowed != Acl::ALLOW) {
$this->flash->error("You do not have permission to access this area.");
$this->response->redirect('site');
//Stops dispatcher at the current operation
return false;
}
}
在我的 ControllerBase 中,我有设置样式和 javascript 集合的函数初始化。
public function initialize()
{
Tag::prependTitle('Fireball |');
$this->assets
->collection('style')
->addCss('third-party/css/bootstrap.min.css', false, false)
->addCss('css/style.css')
->setTargetPath('css/production.css')
->setTargetUri('css/production.css')
->join(true)
->addFilter(new \Phalcon\Assets\Filters\Cssmin());
$this->assets
->collection('js')
->addJs('third-party/js/jqeury.min.js', false, false)
->addJs('third-party/js/bootstrap.min.js', false, false)
->setTargetPath('js/production.js')
->setTargetUri('js/production.js')
->join(true)
->addFilter(new \Phalcon\Assets\Filters\Jsmin());
}
在管理控制器中,我正在调用此函数
public function indexAction()
{
Tag::setTitle('Admin');
parent::initialize();
}
我还有一个基本模板,用于输出这些样式和 javascript 集合的每个视图。问题是即使不允许用户访问此区域,视图也会呈现,这会导致错误“管理器中不存在该集合”。所以集合没有在控制器中设置,但视图试图渲染它。我试图设置一个条件来检查集合是否存在并且它没有按预期工作,因为在我有权访问集合的路由中没有呈现。我的 base.volt 文件:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
{{ get_title() }}
{% if this.assets %}
{{ this.assets.outputCss('style')}}
{{ this.assets.outputJs('js')}}
{% endif %}
{% block head %}
{% endblock %}
</head>
<body>
<div class="navbar navbar-default">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Fireball</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">
<a href="#">Home</a>
</li>
<li>
<a href="#">About</a>
</li>
<li>
<a href="#">Contact</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a href="/signin">Sign in</a>
</li>
</ul>
</div>
</div>
</div>
{{ flash.output() }}
{% block content %}
{% endblock %}
</body>
</html>
还有我的 admin/index.volt (我收到关于收藏的错误的区域)
{% extends "templates/base.volt"%}
{% block head %}
{% endblock %}
{% block content %}
Admin/index
{% endblock %}
那么有人可以帮我解决这个问题吗?