下午好。我有一个很大的问题,我使用一些参数来输入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());
}
}
可以分享视图文件的代码吗? –