In Symfony Ich versuche, einen Loginpage zu erstellen, aber ich bekomme die folgende Fehlermeldung:Symfony Fehler für die Anmeldung
Variable "error" does not exist in QuizBundle:Default:welcome.html.twig at line 37
jemand mir dabei helfen? Hier ist mein Code:
Klasse:
class SecurityController extends Controller
{
public function indexAction($name)
{
return $this->render('', array('name' => $name));
}
/**
* @Route("/welcome", name="welcome")
*/
public function welcomeAction(Request $request)
{
$authenticationUtils = $this->get('security.authentication_utils');
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('@Quiz/Default/welcome.html.twig', array(
// last username entered by the user
'last_username' => $lastUsername,
'error' => $error,
)
);
}
}
Zweig Datei:
<div id="loginfields" style="display: none">
{% if error %}
<div>{{error.messageKey|trans(error.messageData, 'security')}}</div>
{% endif %}
<form class="form-signin" action="{{path('welcome')}}" method="post">
<h2 class="form-signin-heading">Please sign in</h2>
<label class="sr-only" for="username">Username:</label>
<input type="text" id="username" placeholder="Username" class="form-control" name="_username" value="{{ last_username }}"/>
<label class="sr-only" for="password">Password:</label>
<input type="password" id="password" class="form-control" placeholder="Password" name="_password" />
<input type="hidden" name="_target_path" value="/admin" />
<button class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
</div>
security.yml
security:
encoders:
QuizBundle\Entity\User: plaintext
providers:
our_db_provider:
entity:
class: QuizBundle:User
firewalls:
main:
anonymous: ~
form_login:
login_path: welcome
check_path: welcome
Entschuldigung für die späte Antwort. Das Problem ist, dass ich eine login.html.twig-Datei habe, die mit der in meiner Frage geposteten identisch ist, aber in dieser habe ich '
Es macht nichts, es war ein dummer Fehler von meiner Seite, da ich irgendwo anders in einem anderen Controller einen Pfad hatte. – Otonel