Bonjour,
J'ai un problème avec l'affichage d'un message flash.
Dans le fichier nommé UsersController.php J'ai ça:
<?php
App::uses('AppController','Controller');
class UsersController extends AppController{
public function beforeFilter(){
parent::beforeFilter();
$this->Auth->allow('signup','login');
}
public function signup(){
if(!empty($this->request->data))
{
$this->User->create($this->request->data);
if($this->User->validates()){
$token = md5(time().'-'.uniqid());
$this->User->create(array(
'username' => $this->request->data'User']'username'],
'password' => $this->Auth->password($this->request->data'User']'password']),
'mail' => $this->request->data'User']'mail'],
'token' => $token
));
$this->User->save();
App::uses('CakeEmail','Network/Email');
$CakeEmail = new CakeEmail('smtp');
$CakeEmail->to($this->request->data'User']'mail']);
$CakeEmail->subject('votre inscription petsy');
$CakeEmail->viewVars(
$this->request->data'User'] +
array(
'token' => $token,
'id' => $this->User->id
)
);
$CakeEmail->emailFormat('text');
$CakeEmail->template('signup');
$CakeEmail->send();
$this->Session->setFlash('Merci vous êtes inscrit');
}
}
}
}
et dans le view default.ctp j'ai ça:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Bootstrap, from Twitter</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- Le styles -->
<?= $this->Html->css('bootstrap'); ?>
<style type="text/css">
body {
padding-top: 60px;
padding-bottom: 40px;
}
</style>
<?= $this->Html->css('bootstrap-responsive'); ?>
<?= $this->fetch('css'); ?>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<button type="button" class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="brand" href="#">Project name</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li class="divider"></li>
<li class="nav-header">Nav header</li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<form class="navbar-form pull-right">
<input class="span2" type="text" placeholder="Email">
<input class="span2" type="password" placeholder="Password">
<button type="submit" class="btn">Sign in</button>
</form>
</div><!--/.nav-collapse -->
</div>
</div>
</div>
<div class="container">
<?= $this->Session->flash(); ?>
<?= $this->fetch('content'); ?>
</div> <!-- /container -->
<?= $this->Html->script('http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js');?>
<?= $this->Html->script('cakebootstrap'); ?>
<?= $this->fetch('script'); ?>
</body>
</html>
Merci pour votre aide
Salut,
Il te faudrait surement un redirect après le set de ton message flash ^^
Car la en l'état je suppose que une fois le signup effectuer, si tu retourne sur une autre page ta flash message s'affiche