impossible de lire des variables e twig
Bonjour,
je trouve un probléme ou j'envoi des variables de controller vers twig mais quand il lire ses variables en javascript il affiche null mais quand il lire ses variables entwig aussi s'affiche null, quand il faire var_dump et voire resultat qui je trouve en console->network je trouve bien les resultats.
code loginAction:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
public function loginAction() {
$em = $this->getDoctrine()->getManager();
$request = $this->getRequest();
$test = null; $token = null; $res = 'null';
if ($request->getMethod() == 'POST') {
$username = $request->request->get('username');
$password = $request->request->get('password');
$test = $em->getRepository('MedBundle:Med')->findOneBy(array('username' => $username));
if (!($test)) { $res = "error"; } else{
$salt= $test->getSalt();
$pass = crypt($password,$salt);
if ( $pass !== $test->getPassword() ) { $res='error password'; } else {
$res='success';
$token = $this->get('lexik_jwt_authentication.jwt_manager')->create($test);
$test->setToken($token);
$em->persist($test);
$em->flush();
} }
}
return $this->render('default/login.html.twig',array('test' => json_encode($test), 'token' => $token,'res' => json_encode($res)));
} |
code twig (à la fin du page il y'a code javascript):
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| <!DOCTYPE html>
<head>
<meta charset="UTF-8">
<title>Login</title>
<style>
body{
background-color: #525252;
}
.centered-form{
margin-top: 60px;
}
.centered-form .panel{
background: rgba(255, 255, 255, 0.8);
box-shadow: rgba(0, 0, 0, 0.3) 20px 20px 20px;
}
a {
text-decoration:none;
color: #e74c3c;
margin-right: 25px;
}
</style>
</head>
<body>
<div class="container">
<div style="margin-top:50px;" class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Welcome</h3>
</div>
<div class="panel-body">
<form role="form">
<fieldset>
<div class="form-group">
<input class="form-control" placeholder="Username" ng-model="user" name="username" type="text" autofocus>
</div>
<div class="form-group">
<input class="form-control" placeholder="Password" ng-model="pass" name="password" type="password" value="">
</div>
<!-- Change this to a button or input when using this as a form -->
<button type="button" class="btn btn-success btn-block" ng-click="login()">Login</button>
<p onclick="test();">New Member? <a href="signUp.html" class="">Sign up</a></p>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
<script>
function test() {
$.ajax({
type:'GET',
url:"{{path('login')}}",
data:'check',
success:function(response){
console.log('1');
console.log({{res}});
console.log('2');
}
});
}
</script>
</body>
</html> |
comment résoudre ce probléme et merci d'avance