0
cakephpが新しくなっています。ログインフォームの送信ボタンをクリックするとログインフォームが表示されます。同じページ、つまりログインページに戻ります。この問題は、AppControllerからLoginActionを削除すると削除されます。次のように私のコードは次のとおりです。cakephp 3.0で送信ボタンをクリックしたときに次のページにリダイレクトできません
index.ctp
<?php echo $this->Form->create('Login', array('url' => array('controller' => 'Login', 'action' => 'dashboard'))); ?>
<?= $this->Form->input('username'); ?>
<?= $this->Form->input('password'); ?>
<?= $this->Form->submit('Login', array('class' => 'button')); ?>
<?= $this->Form->end(); ?>
AppController.php
$this->loadComponent('Auth',['loginAction' => [
'controller' => 'Login',
'action' => 'index'
],'authenticate' => [
'Form' => [
'userModel' => 'Login', // Added This
'fields' => [
'username' => 'username',
'password' => 'password',
]
]
],'loginRedirect' => [
'controller' => 'Post',
'action' => 'dashboard'
],
]);
LoginController.php
public function dashboard()
{
echo "sample msg";
$this->render('dashboard');
}
public function login(){
if($this->request->is('post')){
$user=$this->Auth->identify();
if($user) {
$this->Auth->setUser($user);
return $this->redirect(['controller'=>'Post']);
}
$this->Flash->error('Incorrect Login');
}
}
しかし、送信ボタンをクリックしても同じログインページが表示されます。私は問題がAppController.phpにあると思う – user3653474
あなたのログインアクションはどこですか?それはユーザーのコントローラに属していますか? –
ユーザコントローラはありませんが、ログインコントローラに属しますが、単に別のビューをレンダリングするダッシュボードアクションを呼び出すと動作しません。 – user3653474