Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig_Error_Syntax: The function "is_granted" does not exist

Tags:

twig

silex

I'm using Silex and can't use the is_granted function in a template. I can't find anything in the docs about why this isn't working. Any hints?

$app->register(new Silex\Provider\SecurityServiceProvider());

$app->register(new Silex\Provider\TwigServiceProvider(), array(
    'twig.path' => __DIR__.'/../templates',
    'twig.options' => array('cache' => __DIR__.'/../cache'),
));

$app['debug'] = true;

$app['security.firewalls'] = array(
    'login' => array(
                'pattern' => '^/login$',
        ),
        'secured' => array(
                'pattern' => '^.*$',
                'form' => array('login_path' => '/login', 'check_path' => '/login_check'),
                'users' => array(
                        'admin' => array('ROLE_ADMIN', '5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='),
                ),
        ),
);

$app->get('/', function() use ($app) {
    return $app['twig']->render('index.html.twig');
});

$app->get('/login', function(Request $request) use ($app) {
    return $app['twig']->render('login.html.twig', array(
            'error'                 => $app['security.last_error']($request),
            //'last_username' => $app['session']->get('_security.last_username'),
    ));
});
like image 457
nvahalik Avatar asked Oct 24 '12 19:10

nvahalik


1 Answers

Apparently, I needed to add the symfony/bridge components as well:

Add this to composer.json and update.

"symfony/twig-bridge": "2.1.*",

And hey... it'll work like expected.

like image 159
nvahalik Avatar answered Sep 24 '22 18:09

nvahalik