我有此代码,但 Flash 消息显示不正确。
我想在以下位置显示消息:
http://xxx/cake/ ----(add action)
但实际上消息显示在:
http://xxx/cake/users/ ----(index action)
我该如何解决这个问题?我对激活没有任何看法。我只想重定向到添加操作并在此之后显示 Flash 消息。
class UsersController extends AppController {
public function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}
public function add() {
}
public function activation() {
$email = $this->request->query['email'];
$codeLink = $this->request->query['code'];
if($this->User->activationAccount($email, $codeLink)) {
$this->Session->setFlash(__('Success'));///should be shown in add
$this->redirect(array('action' => 'add'));
}
else {
$this->Session->setFlash(__('Error.'));//should be shown in add
$this->redirect(array('action' => 'add'));
}
}
}
路由.php
Router::connect('/', array('controller' => 'users', 'action' => 'add'));