我創建了CakePHP 3應用程序,女巫具有登錄功能。登錄功能在我的本地機器上完美運行。但是,在生產服務器上,當登錄憑證是corrcet時,它會將我重定向到「\」而不是我指定的URL。我相信這是Session的問題。我的意思是由於某種原因,會話在重定向線路上丟失了。
的代碼:
的AppController的Initilaize方法
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Flash');
$this->loadComponent('Auth',[
'authenticate'=>[
'Form'=>[
'fields'=>[
'username'=>'username',
'password'=>'password'
],
'finder' => 'auth',
]
],
'loginAction'=>[
'controller'=>'Users',
'action'=>'login'
],
'loginRedirect' => [
'controller'=> 'Pages',
'action'=> 'dashboard'
],
]);
}
UserController.php:
class UsersController extends AppController {
public function initialize()
{
parent::initialize();
}
public function login() {
if ($this->request->is('post')) {
$user=$this->Auth->identify();
if($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
} else {
$this->Flash->error(_('your username or password is incorrect, please try agian'), [
'key' => 'falseSignIn']);
}
}
}
public function logout() {
return $this->redirect($this->Auth->logout());
}
}
你能告訴我你定義loginredirect的應用程序控制器的初始化函數嗎?我在主要問題中添加了 – Aparna
。請看看那裏 – Tanan