2015-10-02 2 views
-3

Моя форма входа в систему отображается, но когда я нажимаю на кнопку входа в систему, ничего не происходит. Я просто приземляюсь на свою регистрационную форму снова и снова. $this->request->data Возвращает пустой массив.CakePHP Login не работает

$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()); 
    } 

} 

?> 

Большинство учебники Дон» t объясните, как кс. Это просто волшебным образом происходит в учебниках. Моя книга cakePHP вообще не реализует функцию login(), она остается пустой.

Я использую CakePHP 2.7.

+0

Ваш вопрос будет лучше, если вы получил ** поставить код в вопросе **, скажем, какую версия CakePHP вы используете [как вы также просили с вашим последним вопросом] (HTTP: //stackoverflow.com/questions/32904879/cakephp-auth-controllername#comment53642270_32904879) и дать немного более подробную информацию, чем «это не сработает» - если у вас нет более подробной информации, вам нужно достаточно отлаживать, чтобы иметь возможность сказать что происходит, прежде чем задавать вопрос. «Вот мой код, что с ним не так?» это не вопрос, который большинство читателей чувствует, как ответ. – AD7six

+0

Я абсолютно не знаком с CakePHP, и я даже не могу сказать, ** что ** не работает – Raildex

ответ

1

вы прошли данные в

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

Это должно быть пустым. как показано ниже:

$this->Auth->login();