CakePHP登录不起作用

时间:2015-10-02 14:51:46

标签: php cakephp

我的登录表单确实显示,但是当我点击我的登录按钮时,没有任何反应。 我一次又一次登陆我的登录表单。 $this->request->data返回一个空数组。

$this->Auth->data返回NULL

这是我的观点(login.ctp):
http://pastebin.com/aW6YSTQx

<?php 
if($this->Session->check('Message.auth')) $this->Session->flash('auth');  
echo $this->Form->create('Veranstalter', array('action' => 'login','url'=>'/veranstalter/login','method'=>'post')); 
?>
<h2>
    Login
</h2>
<table class="input">
    <colgroup>
        <col width="15">
        <col width="75">
    </colgroup>
    <tr>
        <th>
            Veranstalter Nummer
        </th>

        <td>
            <?php echo $this->Form->input('ID',array('type'=>'text','label'=>false)); ?>
        </td>
    </tr>
    <tr>
        <th>
            Passwort
        <td>
            <?php echo $this->Form->input('Passwort',array('label'=>false)); ?>
        </td>
    </tr>
    <tr>
        <th>
            Login
        </th>
        <th>
            <?php echo $this->Form->end('Login');?>
        </th>
    </tr>
</table>

这是我的控制器:
http://pastebin.com/Zk4g11AK

<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of VeranstalterController
 *
 * @author nilsg
 */
class VeranstalterController extends AppController {

    public $uses = array('Veranstalter', 'Land', 'Veranstaltungen', 'Tagungsstaette');
    public $layout = 'main';
    public $helpers = array('Form');
    public $components = array('Flash',
        'Auth','Session');

    function beforeFilter() {
        parent::beforeFilter(); {
            $this->Auth->loginAction = array('controller'=>'Veranstalter','action'=>'login');
            $this->Auth->loginRedirect = array('controller'=>'Veranstalter','action'=>'index');
            $this->Auth->logoutAction = array('controller'=>'Veranstalter','action'=>'login');
            $this->Auth->userModel = 'Veranstalter';
            $this->Auth->allow =array('index');
            $this->Auth->fields = array('username'=>'ID','password'=>'Passwort');
        }
    }

    function index() {
        $this->set('Veranstalter', $this->Veranstalter->find('all', array('recursive' => 4)));
    }

    function add() {
        $this->set('laender', $this->Land->find('list'));
        if (!empty($this->data)) {
            if ($this->Veranstalter->validates()) {
                $this->Veranstalter->create();
                if ($this->Veranstalter->save($this->data)) {
                    $this->Session->setFlash('Der Antrag wurde gespeichert.');
                    $this->redirect(array('action' => 'index'));
                } else {
                    $this->Veranstalter->setFlash('Der Antrag konnte nicht angelegt werden.');
                }
            }
        }
    }

    public function login() {
       if ($this->request->is('post')) {
            if ($this->Auth->login($this->request->data)) {
                return $this->redirect($this->Auth->redirectUrl());
            }
            $this->Flash->error(__('Invalid username or password, try again'));
        }
    }

    function edit($id = null) {
        $this->set('laender', $this->Land->find('list'));

        $this->Veranstalter->id = $id;
        if (empty($this->data)) {
            $this->data = $this->Veranstalter->read();
        } else {
            if ($this->Veranstalter->save($this->data)) {

                $this->Session->setFlash('Der Antrag wurde gespeichert');
                $this->redirect(array('action' => 'index'));
            }
        }
    }

    function delete($id = null) {
        $this->Veranstalter->delete($id, false);
        $this->redirect(array('action' => 'index'));
    }

    function logout() {

        $this->redirect($this->Auth->logout());
    }

}

?>

大多数教程都没有解释Login如何工作。它只是神奇地发生在教程中。 我的cakePHP Book根本没有实现login()功能,它保持空白。

我正在使用CakePHP 2.7。

1 个答案:

答案 0 :(得分:2)

您已在

中传递了数据
$this->Auth->login($this->request->data)

一定是空白。如下所示:

$this->Auth->login();
相关问题