Yii Framework Forum: onBeforeSave problem - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

onBeforeSave problem Rate Topic: -----

#1 User is offline   dimis283 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 277
  • Joined: 24-January 09

Posted 22 September 2009 - 08:15 AM

I have a user register (not from Yii crud) page and I want the pass to be md5(pass) so I write this code that does not work, what is wrong?
public function onBeforeSave($event) {
        $pass = md5($this->usr_pass);
        $this->usr_pass= $pass;

        //   $this->usr_pass=md5( $this->usr_pass);
        //  $this->password_repeat=md5( $this->password_repeat);
        //  die( $this->usr_pass);
        return true;

    }

Posted Image
0

#2 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,016
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 22 September 2009 - 08:23 AM

The method should be called "beforeSafe".
0

#3 User is offline   francisco 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 07-November 10

Posted 09 December 2010 - 04:27 PM

Try something like this (in the Model):

public function init(){
$this->onBeforeSave=array($this,'crypt');
parent::init();
}

public function crypt($event) {
$model = $event->sender;
$pass = md5($model->usr_pass);
$model->usr_pass= $pass;
$event->isValid=true
return true;
}
0

#4 User is offline   m.h.ameen 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 2
  • Joined: 08-June 11

Posted 12 September 2011 - 11:59 AM

public function beforeSave() {
$pass = md5($this->usr_pass);
$this->usr_pass= $pass;

// $this->usr_pass=md5( $this->usr_pass);
// $this->password_repeat=md5( $this->password_repeat);
// die( $this->usr_pass);
return true;

}


works with me
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users