单击cakephp 3.0中的提交按钮时无法重定向到下一页

时间:2017-01-17 14:26:18

标签: php cakephp cakephp-3.0

我是cakephp的新手我有一个表单,这是一个登录表单,点击登录表单提交按钮页面没有重定向。它返回到同一页面,即登录页面。当我从AppController中删除LoginAction时,问题被删除。我的代码如下:

  

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');
       }  
    }

1 个答案:

答案 0 :(得分:0)

如果您的问题与重定向有关,只需将其添加到相应的控制器中:

public function initialize()
{
    parent::initialize();
    $this->Auth->allow(['dashboard']); // your actions list
}

如果您需要在登录成功之前访问它们,则需要允许操作。