繁体   English   中英

CakePHP 登录不起作用

[英]CakePHP Login does not work

我的登录表单确实出现了,但是当我点击我的登录按钮时,什么也没有发生。 我只是一次又一次地登陆我的登录表单。 $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());
    }

}

?>

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

我正在使用 CakePHP 2.7。

你已经传递了数据

$this->Auth->login($this->request->data)

它必须是一个空白。 像下面这样:

$this->Auth->login();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM