volt
A Ruby web framework where your Ruby runs on both server and client
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" rel='nofollow' href="#">Fireball</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="active">
<a rel='nofollow' href="#">Home</a>
</li>
<li>
<a rel='nofollow' href="#">About</a>
</li>
<li>
<a rel='nofollow' href="#">Contact</a>
</li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li>
<a rel='nofollow' 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?
Source: (StackOverflow)
I write modular app and want common path (Volt layouts) for all modules.
$view->setLayoutsDir(PATH_APP . '/common/layouts/'); // don't solved problem
{% extends "../../../common/layouts/base.volt" %} // so ugly
{% extends common_layouts ~ "base.volt" %} /* return error
"Syntax error, unexpected token IDENTIFIER(common_layouts)..." */
P.S.: not forgotten about:
$view->setVar('common_layouts', PATH_APP . '/common/layouts/');`
Do u have solution?
Source: (StackOverflow)
I want to redeclare and add some methods to helper Tag.
class MyTags extends \Phalcon\Tag
{
public static function mytag($params)
{
<...>
}
}
in services.php
$di->set('tag', function() {
return new MyTags();
};
But it works only for PHP engine, not for Volt.
{{ mytag() }}
returned
Undefined function 'mytag'
Source: (StackOverflow)
How can I set a 404 page in Phalcon to be displayed when a controller/action does not exist?
Source: (StackOverflow)
I want to be able to have syntax highlighting in PHPStorm for Volt, Phalcon's template engine.
Is there a way to do so?
Source: (StackOverflow)
I do not understand why a developer would use phalcon Volt template engine.
Because in the end, after the compilation the same PHP files are produced, that I can write manually in the first place. To me, it looks only to be detrimental to the performance.
Is the answer - "so you could pass .volt files to a front-end guy"?
Thanks,
Temuri
Source: (StackOverflow)
I have a section in ini files with some globally used social links, for ex:
[social]
fb = URL
twitter = URL
linkedin = URL
What's the easiest way to access these, or is there a better way to organize these global variables?
Source: (StackOverflow)
How can I set up a user defined function in Volt? For instance I want to call a function that would translate strings in my views as such:
<div class='page-header'>
<h2>{{ tr('session_login_title') }}</h2>
</div>
and I want the tr
to map to a function \My\Locale::translate($key)
Source: (StackOverflow)
I'm working with Phalcon in Netbeans. I see I can use twig plugin for template highlighting for volt files. I am using phtml files and want highlighting for volt (twig) and php. Is this possible?
Also related - Netbeans keeps duplicating my phtml view files and adding the extention .phtml.php to them. How can I fix that?
Source: (StackOverflow)
Hi I am developing a website using phalcon. My homepage is divided into header index and footer. The header has a menu bar which is common to all other pages but for the login page I don't want this menu bar. How to hide this menu bar code only in the login page? Please help me.
My menu bar code is
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav main_menu">
<li><?php echo Phalcon\Tag::linkTo(array('index', '<img src="images/home.png">'));?></li>
<li><?php echo Phalcon\Tag::linkTo(array('my-sale', '<img src="images/mysale.png">'));?></li>
<li><?php echo Phalcon\Tag::linkTo(array('customers', '<img src="images/customers.png">'));?></li>
<li><?php echo Phalcon\Tag::linkTo(array('campaign', '<img src="images/campaign.png">'));?></li>
<li><?php echo Phalcon\Tag::linkTo(array('analysis', '<img src="images/analysis.png">'));?></li>
<li><?php echo Phalcon\Tag::linkTo(array('myaccount', '<img src="images/myaccount.png">'));?></li>
</ul>
</div>
How to hide this menu bar code in my login page?
Please help.
Source: (StackOverflow)
I am trying to create macro for my templates like this:
{%- macro bField(form, name, attributes) %}
<p class="form-group" ng-class="{has-error: !{{ form.name }}.{{ name }}.$valid}">
{{ form.label(name) }}
{#{% set attributes['class'] = 'form-control' %}#}
{{ form.render(name, attributes) }}
{% include 'forms/validation-messages.volt' %}
</p>
{%- endmacro %}
The issue is it is in macros.volt file in views root and I dont have any idea how or where to include it so it is available everywhere. I tried in root layout (index.volt) with include and partial functions but still doesnt work. Not even in template file I am trying to use it in.
What am I doing wrong, how to fix this?
Another thing is how do I set value on certain key in array. I obviously tried {% set attributes['class'] = 'form-control' %}
, but it doesnt work.
Source: (StackOverflow)
In phalcon templating engine volt (which is similar to twig) you can fetch all records by :
{% for product in products %}
Name: {{ product.name }}
Description: {{ product.description }}
price: {{ product.price}}
{% endfor %}
So, in my scenario, I'm building a crud template which will be used for different kind of models. What I wanted to achieve in this template is that every columns in this view are not hard-coded. So I store the columns I wanted to show into an array (defined in the controller, passed to the view) :
$cols = ['name','description','price']
In the view, to make it display all columns :
{% for product in products %}
{% for col in cols %}
{{ col }}: {{ product.col }}
{% endfor %}
{% endfor %}
Obviously, this will result in error, because there is no "col" in product.
Is there any solution or alternative for this ?
Source: (StackOverflow)
From what I understand, Phalcon uses index.phtml
or index.volt
in app/views
as the base template for any page that doesn't have a template specified.
How can I change this to use app/views/layouts/common.volt
?
Source: (StackOverflow)
The error I am getting is
Warning: Phalcon\Mvc\View\Engine\Volt\Compiler::compileFile(../app/views/index/index.phtml.php): failed to open stream: Permission denied in /Users/mattstephens/Sites/magpie/public/index.php on line 26 Phalcon Exception: Volt directory can't be written
I have declared the volt engine usage in my bootstrap like so
$view->registerEngines(array(
'.phtml' => 'Phalcon\Mvc\View\Engine\Volt'
));
The mention of line 26 in my code points to the application handle function shown below
echo $application->handle()->getContent();
Is this a permissions related thing or due to a missing directory?
Source: (StackOverflow)
In Volt (the template engine for Phalcon) how can I get the number of elements in an array? I've tried sizeof
and also count
, length
and size
(hoping to stumble upon the correct command).
In this particular instance I'm just interested in whether there are >0 elements but in the future it would be handy to be able to get the actual number.
Source: (StackOverflow)