Reputation: 349
I am having a little error with phalcon's acl. I have function beforeExecuteRoute which either allows or denies user with a role to access specific controller/action.
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;
}
}
In my ControllerBase I have function initialize that sets up the collections of styles and 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());
}
And in admin controller I am calling this function
public function indexAction()
{
Tag::setTitle('Admin');
parent::initialize();
}
I also have a base template in volt for every view in which I output those collections of styles and javascript. The problem is that the view is getting rendered even if user is not allowed to access this area and this causes an error "The collection does not exist in the manager". So the collection is not set up in controller but the view tries to render it. I tried to put a condition to check if collection exists and it didn't work as expected cause in the routes that I have access to the collections were not rendered. My base.volt file:
<!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>
And my admin/index.volt (the area I am getting an error about a collection)
{% extends "templates/base.volt"%}
{% block head %}
{% endblock %}
{% block content %}
Admin/index
{% endblock %}
So could anybody help me to resolve this issue?
Upvotes: 1
Views: 1203
Reputation: 612
This is the fireball tutorial codes from Jesse Boyer right? Try to reset your routing or set your url as he did his custom routing for his virtualbox.
Try to put this in your index.php in your public folder for the dependencies:
$di->set('url', function () use ($di) {
$url = new \Phalcon\Mvc\Url();
$dispatcher = $di->getShared('dispatcher');
$url->setBaseUri('');
return $url;
});
Upvotes: 1