PHP code example of falconchen / slim-twig-csrf-inputs
1. Go to this page and download the library: Download falconchen/slim-twig-csrf-inputs library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
falconchen / slim-twig-csrf-inputs example snippets
...
// 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;
};
...