register(new Silex\Provider\-6ren">
gpt4 book ai didi

Twig_Error_Syntax : The function "is_granted" does not exist

转载 作者:行者123 更新时间:2023-12-04 16:40:22 24 4
gpt4 key购买 nike

我正在使用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'),
));
});

最佳答案

显然,我还需要添加symfony/bridge组件:

将此添加到composer.json并更新。

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

嘿...它会像预期的那样工作。

关于Twig_Error_Syntax : The function "is_granted" does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13056139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com