Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 多个登录表单提交到一个登录操作_Php_Authentication_Cakephp - Fatal编程技术网

Php 多个登录表单提交到一个登录操作

Php 多个登录表单提交到一个登录操作,php,authentication,cakephp,Php,Authentication,Cakephp,我的(蛋糕)应用程序中有两个登录表单。一个在主页上(由pages controller提供服务),一个在我的用户控制器中。来自我的用户控制器的一个工作正常。但是当我尝试从主页登录时,我得到了一个空白页面,我在firebug中看到了404。奇怪的是,会话设置正常 看起来它与$this->Auth->autoRedirect=false(在用户控制器beforeFilter()中设置)有关。有什么问题吗 我的登录操作如下所示: function login() { /* Werkt

我的(蛋糕)应用程序中有两个登录表单。一个在主页上(由pages controller提供服务),一个在我的用户控制器中。来自我的用户控制器的一个工作正常。但是当我尝试从主页登录时,我得到了一个空白页面,我在firebug中看到了404。奇怪的是,会话设置正常

看起来它与$this->Auth->autoRedirect=false(在用户控制器beforeFilter()中设置)有关。有什么问题吗

我的登录操作如下所示:

  function login()
  {
    /* Werkt nog niet vanuit `home login` */
    if ($this->Auth->user())
    {
      if(!empty($this->data))
      {
        /* Update last login */
        $this->User->id = $this->Auth->user('id');
        $this->User->saveField('last_login', date('Y-m-d H:i:s'));
      }
      $this->redirect($this->Auth->redirect());
    }
  }

当您设置
$this->Auth->autoRedirect=false
时,您需要在登录尝试后在login()方法中手动重定向<代码>$this->redirect($this->referer())。我猜,你有空白页是因为没有重定向或重定向错误。那个空白页面的url是什么?

在尝试了我能想到的一切之后,我最后的希望是不要使用(默认)页面控制器。因此,我所做的是将其复制到我的应用程序/控制器,并使其看起来像:

<?php
class PagesController extends AppController
{
  var $name = 'Pages';
  var $uses = array();

  var $__allowUnAuthorized = array('*');
  var $__allowAuthorized = array();

  function beforeFilter()
  {
    parent::beforeFilter();

    $this->Auth->allow($this->__allowUnAuthorized);
  }

  function display()
  {
    // Same as default
  }
}


现在一切都很好!可能与pages controller无权访问$this->Session或$this->Auth有关?

尝试将调试级别设置为3,然后编辑问题以包含该级别的输出。调试已在3上,但没有输出(或错误)。你想看什么?调试($this)?检查主页登录表单的结果html中的表单操作。表单操作正确。我已登录,但仍收到404作为响应。但是只有当:$---> Auth-> AutoReTrime=空白页的URL是/站点/用户/登录,但是在我的动作中,我有一个重定向,就像上面的一个。然而,奇怪的是,我在login()中输入的所有内容都没有执行(当从用户控制器外部请求时)。甚至当我把它放在开始的时候…嘿,我和你有同样的问题。你有没有发现更好的方法?
<?php
class AppController extends Controller
{
  var $name = 'App';
  var $components = array('Auth', 'Security', 'Session');
  var $helpers = array('Html', 'Form', 'Session');

  function beforeFilter()
  {
    parent::beforeFilter();

    /* Auth */
    $this->Auth->autoRedirect = false;

    $this->Auth->loginAction = array(
      'controller' => 'users',
      'action' => 'login'
    );
    $this->Auth->loginRedirect = array(
      'controller' => 'users',
      'action' => 'index'
    );
    $this->Auth->loginError = __(
      'Ongeldige conbinatie van gebruikersnaam en wachtwoord', true
    );
    $this->Auth->authError =  __(
      'U bent niet bevoegd om deze pagina te bekijken' ,true
    );

    $this->Session->delete('Auth.redirect');
  }
}
?>