开发者

beforeSave() returned some error

开发者 https://www.devze.com 2023-01-03 18:41 出处:网络
I got two simple input text fields in a HTML form: <input type=\"text\" name=\"data[User][name]\" id=\"data[User][name]\">

I got two simple input text fields in a HTML form:

<input type="text" name="data[User][name]" id="data[User][name]">   
<input type="text" name="data[User][pswd]" id="data[User][pswd]">    

The scripts for the Controller's action that captured the data is as follows:

 function register(){ 
          $temp = $this->data;                       
          if(strlen($temp['User']['pswd'])>6) {           
            if ($this->User->save($this->data)) {
            $this->Session->setFlash('Data was Saved');         
                                                }
                                   }           
        } // this script works

And in the Model controller, I got these lines o开发者_StackOverflowf codes:

  function beforeSave() {
     $raw = $this->data;
 if(strlen($raw['User']['pswd'])>6){
     md5($raw['User']['pswd']);        
 }
 return true;
                         } // this script failed to work

The data was stored into the Database successfully but it was not undergone any MD5 encryption.

I think that there must be some errors in the Model's script because I saw some errors

flashed after the data was saved, but the screen that showed the errors

immediately refreshed in a second after the data was saved successfully

and I couldn't see the detail of the errors that caused the problem.

Could you help me out please?

Edited:

I have altered the code of beforeSave, but it still fails to work:

function beforeSave() {
     $raw = $this->data;
 if(strlen($raw['User']['pswd'])>3){
     $raw['User']['pswd'] = md5($raw['User']['pswd']);      
 }
 return true;
                         }


$raw is a local variable and hence doesn't exist outside of the beforeSave method. Depending on your use case you could simply override the value submitted by the user:

$this->data['User']['pswd'] = md5($raw['User']['pswd']);

0

精彩评论

暂无评论...
验证码 换一张
取 消