我正在使用 CakePHP 2.6.7 并复制代码以显示从一个控制器到另一个控制器的闪存消息,但它在第二个控制器中不起作用。
在 AdminsController 中:
function login() {
$this->loadModel('Admin');
$this->layout = "admin-login";
// if already logged in check this step
if ($this->Auth->loggedIn()) {
return $this->redirect('dashboard'); //(array('action' => 'deshboard'));
}
// after submit login form check this step
if ($this->request->is('post')) {
if ($this->Auth->login()) {
// pr($this->Auth); exit;
if ($this->Auth->user('status') == 'active') {
// user is activated
$this->Admin->id = $this->Auth->user('id');
$this->Admin->saveField("loggedIn", 1);
return $this->redirect($this->Auth->redirectUrl());
} else {
// user is not activated
// log the user out
$msg = '<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>You are blocked, Contact with Adminstrator</strong>
</div>';
$this->Session->setFlash($msg);
return $this->redirect($this->Auth->logout());
}
} else {
$msg = '<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Incorrect email/password combination. Try Again</strong>
</div>';
$this->Session->setFlash($msg);
}
}
}
在管理员/login.ctp 中:
<?php echo $this->Session->flash(); ?>
当我输入错误的电子邮件或密码时,它会显示错误消息。证明:http: //jegeachi.com/admins/login
但是无法在 ResellersController 中完成相同的任务。这是控制器代码:
function login() {
$this->layout = 'public-login';
$this->loadModel('Reseller');
// if already logged in check this step
if ($this->Auth->loggedIn()) {
return $this->redirect('profile'); //(array('action' => 'deshboard'));
}
// after submit login form check this step
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirectUrl());
} else {
$msg = '<div class="alert alert-error">
<button type="button" class="close" data-dismiss="alert">×</button>
<strong>Incorrect email/password combination. Try Again</strong>
</div>';
$this->Session->setFlash($msg);
}
}
}
在经销商/login.ctp 中:
<?php echo $this->Session->flash(); ?>
当由于错误的电子邮件或密码而登录失败时,它不会被显示。
证明:http: //jegeachi.com/resellers/login
这是一个奇怪的有线问题。相同的代码在控制器中工作,但在其他控制器中不起作用。任何的想法?