2010-10-27 73 views
1

我使用的帳戶控制器沒有自己的表,但使用用戶模型。Cakephp驗證

所有工作正常,除非 - 當我驗證任何形式。它說,驗證失敗(當我嘗試失敗的驗證檢查),但犯規扔場下面的錯誤

查看

<?php echo $this->Form->input('id'); ?> 
       <label for="UserPassword">New Password:</label> 
       <?php echo $this->Form->text('password', array('type' => 'password', 'value' => 'harsha')); ?><em>Password must be min 6 characters.</em> <?php echo $form->error('password'); ?> 

控制器動作

  if($this->User->saveField('password', $this->data['User']['password'], array('validate' => 'first'))) { 
       $this->Session->setFlash('Password has been changed.', 'flash-success'); 
      } else { 
       $this->Session->setFlash('There was some problem with our system. Please try after some time.', 'flash-warning'); 
      } 

回答

3

嘗試debug()荷蘭國際集團的內容$this->validationErrors在您的視圖中,以及在您的控制器$this->data剛剛提交表單。這應該會給你更多的信息。

我懷疑你的問題是蛋糕是基於錯誤的模型建築形式輸入 - 建築形式字段Account.idAccount.password代替User.idUser.password。這是因爲FormHelper從其控制器/視圖中調用它的默認模型,在您的情況下出現AccountsController

爲了生成控制器提交處理期望的User.idUser.password字段,您需要在FormHelper調用中預先配置User.。因此:

$this->Form->input('User.id'); 
$this->Form->text('User.password'); 
2

你試過:

echo $session->flash();

請注意,不管手冊如何,它都會返回,而不是回聲。我記錄了一段時間,它已在1.3手冊中更改,但不是1.2。

1

嗨,你是誰問
如果你想顯示錯誤消息,從的usermodel的validate返回
所以,你也可以在波紋管輸入形式的密碼添加一行代碼

<?php 
     if ($this->Form->isFieldError('password')) { 
     echo $this->Form->error('password', array('class' => 'error')); 
    ?> 

,如果你想顯示錯誤 - 消息通過方法setFlash設置
必須重定向頁面,然後在頁面中使用$這 - >會話級>閃存(「閃電名」)要顯示它

<?php 
    //in UsersController 
    $this->Session->setFlash('message here', 'flash-name'); 
    //in view 
    echo $this->Session->flash('flash-name'); 
    ?> 

祝你好運!