我正在尝试获取旧的输入值,并使用twig将其显示为默认值。
有这样的事情:
{{ form_widget(form.numeroCIN, {'attr': {'class': 'form-control', value:'{% if form.vars.old.fieldName %} {{form.vars.old.fieldName}} {% endif %}'}}) }}
答案 0 :(得分:0)
创建中间件类:
class OldInputMiddleware extends Middleware
{
public function __invoke ($request, $response, $next)
{
$this->container->view->getEnvironment()->addGlobal('old', $_SESSION['old']);
$_SESSION['old'] = $request->getParams();
$response = $next($request, $response);
return $response;
}
}
将其注册到App.php(我的默认引导文件)
$app->add(new \App\Middleware\OldInputMiddleware($container));
):
安装完Twig模块后,您可以调用输入的旧值(发布失败后):
value="{{old.Name}}