变量“错误"在第 5 行的 FOSUserBundle::layout.html.twig 中不存在 [英] Variable "error" does not exist in FOSUserBundle::layout.html.twig at line 5
本文介绍了变量“错误"在第 5 行的 FOSUserBundle::layout.html.twig 中不存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在网站上工作,但是当我转到'http:/时出现错误/localhost/Tolkien_Bestiaire/web/app_dev.php/profile/'
I'm working on website but I have an error when I go to 'http://localhost/Tolkien_Bestiaire/web/app_dev.php/profile/'
错误:
变量错误"在 FOSUserBundle::layout.html.twig 中不存在第 5 行"
"Variable "error" does not exist in FOSUserBundle::layout.html.twig at line 5"
我使用 FosUserBundle.
I use FosUserBundle.
layout.html.twig:
{% extends "TolkienCoreBundle::layout.html.twig" %}
{% block body %}
{% if error %}
<div class="alert alert-danger">{{ error.message }}</div>
{% endif %}
<form action="{{ path('fos_user_security_check') }}" method="post" id="loginForm">
<label for="username">Pseudo :</label><br/>
<input type="text" id="username" name="_username" value="{{ last_username }}" class="col-md-4"/><br/><br/>
<label for="password" class="col-md-12">Mot de passe :</label><br/>
<input type="password" id="password" name="_password" class="col-md-4"/><br/><br/>
<input type="submit" value="Connexion" class="col-md-4" />
</form>
{% endblock %}
security.yml :
security:
encoders:
Tolkien\UserBundle\Entity\User: sha512
role_hierarchy:
ROLE_ADMIN: [ROLE_AUTEUR, ROLE_MODERATEUR]
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]
providers:
main:
id: fos_user.user_provider.username
firewalls:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
main:
pattern: ^/
anonymous: true
provider: main
form_login:
login_path: fos_user_security_login
check_path: fos_user_security_check
default_target_path: tolkien_bestiaire_home
logout:
path: fos_user_security_logout
target: /tolkien
remember_me:
secret: %secret%
access_control:
- { path: ^/admin, roles: ROLE_ADMIN }
CoreController.php(扩展到layout.html.twig的控制器):
CoreController.php (The controller of the extand to layout.html.twig) :
<?php
namespace Tolkien\CoreBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
class CoreController extends Controller
{
public function indexAction()
{
return $this->render('TolkienCoreBundle:Core:index.html.twig');
}
public function contactAction(Request $request)
{
$session = $request->getSession();
$session->getFlashBag()->add('info', 'La page de contact n’est pas encore disponible, merci de revenir plus tard.');
return $this->redirectToRoute('tolkien_core_home');
}
}
谢谢:)
推荐答案
解决方案是将错误包装在另一个如果:
Solution is to wrap error in another if:
{% if error is defined %}
{% if error %}
... do something with error message
{% endif %}
{% endif %}
在登录的 Twig 模板中.
in Login's Twig template.
这篇关于变量“错误"在第 5 行的 FOSUserBundle::layout.html.twig 中不存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文