2016-03-02 42 views
1

我在CakePHP中從UsersController中的forget_password方法中獲取此錯誤。使用鍵`action`已棄用,直接使用`url`來代替cakephp

public function forgot_password() { 
    $this->layout = 'signin'; 
    if (!empty($this->data)) { 
     $user = $this->User->findByUsername($this->data['User']['username']); 
     if (empty($user)) { 
      $this->Session->setflash('Sorry, the username entered was not found.'); 
      $this->redirect('/users/forgot_password'); 
      }else{ 
       $user = $this->__generatePasswordToken($user); 
       if ($this->User->save($user) && $this->__sendForgotPasswordEmail($user['User']['id'])) { 
       $this->Session->setflash('Password reset instructions have been sent to your email address. 
        You have 24 hours to complete the request.'); 
       $this->redirect('/users/login'); 
      } 
     } 
    } 
} 

這裏是forgot_password.ctp文件

<header class="panel-heading text-center"> 
    <strong>Forget Password</strong> 
</header> 
    <h3>Enter Your Username</h3> 
<?php 
    echo $this->Form->create('User', array('action' => 'forgot_password', 'id' => 'web-form', 'class'=>'panel-body wrapper-lg')); 

    echo $this->Form->input('username', array('label' => 'Username', 'between'=>'<br />', 'type'=>'text', 'div' => 'form-group','class' => 'form-control input-lg')); 
?> 
<div class="form-group"> 
    <?php echo $this->Form->submit('Send Password Reset Instructions', array('class' => 'btn btn-primary btn-techuz', 'id' => 'submit')); ?> 
</div> 
<?php echo $this->Form->end(); ?> 

回答

0

得到了解決,沒有必要提及在forgot_password.ctp文件「動作」 =>「forgot_password」直到它重定向到另一個方法。

3

如果與視圖相同,則無需指定表單操作。如果你想重定向到一個不同的動作,試試這個:

<?php 
     echo $this->Form->create('User', array(
      'url' => array(
       'controller' => 'users','action' => 'forgot_password' 
      ), 
      'id' => 'web-form', 
      'class' =>'panel-body wrapper-lg' 
     ) 
    ); ?> 

如果按照慣例,定義這個「URL」指數作爲控制器和索引的數組,你一定是安全的並失去了錯誤。

和平! xD

+0

完美!!!它聽起來好多了......非常感謝你......:D –

相關問題