我在网站上工作,但是当我去http://localhost/Tolkien_Bestiaire/web/app_dev.php/profile/'
时出现错误错误:
"变量"错误"在FOSUserBundle :: layout.html.twig中不存在 第5行"
我使用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的extand的控制器):
<?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');
}
}
谢谢:)
答案 0 :(得分:1)
解决方案是在以下情况下将错误包装在另一个中:
{% if error is defined %}
{% if error %}
... do something with error message
{% endif %}
{% endif %}
在登录的Twig模板中。