douchi0028 2015-10-02 14:51
浏览 23

CakePHP登录不起作用

My Login Form does Show up, but when I click on my Login Button, nothing happens. I just land onto my Login form again and again. $this->request->data Returns an empty Array.

$this->Auth->data Returns NULL

This is my View (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>

This is my Controller:
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());
    }

}

?>

Most tutorials don't explain how the Login works. It just magically happens in the tutorials. My cakePHP Book doesn't implement a login() function at all, it stays empty.

I'm using CakePHP 2.7.

  • 写回答

1条回答 默认 最新

  • dsfdfd1211 2015-10-03 07:33
    关注

    you have passed data in the

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

    It must be a blank. like below:

    $this->Auth->login();
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line