falconchen/slim-twig-csrf-inputs
Composer 安装命令:
composer require falconchen/slim-twig-csrf-inputs
包简介
A slim twig template extension for easy appending the hidden csrf inputs fields
关键字:
README 文档
README
A slim twig template extension for easy appending the hidden csrf inputs fields.
usage:
load the extension in the dependecies.php, also need to load \Slim\Csrf\Guard into dependecies.
...
// Load Twig
$container['view'] = function ($c) {
$settings = $c->get('settings');
$view = new \Slim\Views\Twig($settings['view']['template_path'], $settings['view']['twig']);
// Add extensions
$view->addExtension(new Slim\Views\TwigExtension($c->get('router'), $c->get('request')->getUri()));
$view->addExtension(new Twig_Extension_Debug());
// add the twig csrf inputs here
$view->addExtension(new FalconChen\Slim\Views\TwigExtension\CsrfInputs($c->csrf));
return $view;
};
//need to load csrf
$container['csrf'] = function ($c) {
$guard = new \Slim\Csrf\Guard();
$guard->setFailureCallable(function ($request, $response, $next) {
$request = $request->withAttribute("csrf_status", false);
return $next($request, $response);
});
return $guard;
};
...
then in twig templates , call the csrf_inputs() function.
<form action="login" method="post" autocomplete="off">
{{ csrf_inputs() }}
...
output :
<input type="hidden" name="csrf_name" value="csrf653024471">
<input type="hidden" name="csrf_value" value="1924fe05051c809802334ab0601aeaa1">
统计信息
- 总下载量: 9
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0
- 更新时间: 2019-06-25