下午好。我有一個很大的問題,我使用一些參數來輸入ajax,但是當我發送ajax到這個代碼時,它只是簡單地重定向而不做任何事情。我相信你有一個更好的方法,但文檔沒有解釋任何東西!如果你能幫助我,謝謝!Cakephp 3 - Ajax登錄
class ContaController extends AppController {
public function initialize() {
parent::initialize();
$this->loadComponent('Flash');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'fields' => ['username' => 'email', 'password' => 'senha'],
'userModel' => 'Conta',
]
],
'loginAction' => [
'controller' => 'Conta',
'action' => 'index'
],
'loginRedirect' => [
'controller' => 'Conta',
'action' => 'minhaAgenda'
],
'logoutRedirect' => [
'controller' => '/'
],
'storage' => 'Memory'
]);
$this->Auth->allow(['index']);
}
public function index() {
if ($this->request->is('ajax') || $this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
echo 'success';
} else {
echo 'incorrect';
}
}
}
public function sair() {
return $this->redirect($this->Auth->logout());
}
}
可以分享視圖文件的代碼嗎? –