我正在使用 Silex,无法在模板中使用 is_granted 函数。我在文档中找不到任何关于为什么这不起作用的信息。有什么提示吗?
$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'),
));
});