beforeSave() Problema

Olá gente, eu tenho uma classe User como essa:




<?php


/**

 * This is the model class for table "users".

 *

 * The followings are the available columns in table 'users':

 * @property integer $id

 * @property string $username

 * @property string $password

 * @property string $email

 * @property string $first_name

 * @property string $last_name

 * @property string $date_born

 * @property string $picture

 * @property string $sex

 * @property string $description

 * @property string $facebook

 * @property string $twitter

 * @property string $date_register

 * @property integer $receive_email

 * @property string $date_last_edit

 * @property integer $edit_count

 * @property string $last_time_logged_in

 *

 * The followings are the available model relations:

 * @property Location[] $locations

 * @property Location[] $locations1

 * @property Messages[] $messages

 * @property Messages[] $messages1

 * @property Photos[] $photoses

 * @property UserBadge[] $userBadges

 * @property UserEvent[] $userEvents

 * @property UserUser[] $userUsers

 * @property UserUser[] $userUsers1

 */

class User extends CActiveRecord {


    /**

     * Returns the static model of the specified AR class.

     * @param string $className active record class name.

     * @return User the static model class

     */

    public static function model($className=__CLASS__) {

        return parent::model($className);

    }


    /**

     * @return string the associated database table name

     */

    public function tableName() {

        return 'users';

    }


    /**

     * @return array validation rules for model attributes.

     */

    public function rules() {

        // NOTE: you should only define rules for those attributes that

        // will receive user inputs.

        return array(

            array('username, password, email, first_name, last_name, date_born, date_register', 'required'),

            array('email', 'email', 'message' => 'Isso daí não parece um email em...'),

            array('receive_email, edit_count', 'numerical', 'integerOnly' => true),

            array('username, password, email, first_name, last_name', 'length', 'max' => 45),

            array('picture', 'length', 'max' => 100),

            array('sex', 'length', 'max' => 1),

            array('description', 'length', 'max' => 800),

            array('facebook, twitter', 'length', 'max' => 150),

            array('date_last_edit, last_time_logged_in', 'safe'),

            array('date_register', 'default', 'value' => new CDbExpression('NOW()')),

            // The following rule is used by search().

            // Please remove those attributes that should not be searched.

            array('id, username, password, email, first_name, last_name, date_born, picture, sex, description, facebook, twitter, date_register, receive_email, date_last_edit, edit_count, last_time_logged_in', 'safe', 'on' => 'search'),

        );

    }


    /**

     * @return array relational rules.

     */

    public function relations() {

        // NOTE: you may need to adjust the relation name and the related

        // class name for the relations automatically generated below.

        return array(

            'locations' => array(self::HAS_MANY, 'Location', 'user_id'),

            'locations1' => array(self::HAS_MANY, 'Location', 'date_last_edit_user_id'),

            'messages' => array(self::HAS_MANY, 'Messages', 'from_user_id'),

            'messages1' => array(self::HAS_MANY, 'Messages', 'to_user_id'),

            'photoses' => array(self::HAS_MANY, 'Photos', 'owner_id'),

            'userBadges' => array(self::HAS_MANY, 'UserBadge', 'user_id'),

            'userEvents' => array(self::HAS_MANY, 'UserEvent', 'user_id'),

            'userUsers' => array(self::HAS_MANY, 'UserUser', 'added_user_id'),

            'userUsers1' => array(self::HAS_MANY, 'UserUser', 'received_user_id'),

        );

    }


    /**

     * @return array customized attribute labels (name=>label)

     */

    public function attributeLabels() {

        return array(

            'id' => 'ID',

            'username' => 'Usuário',

            'password' => 'Senha',

            'email' => 'Email',

            'first_name' => 'Primeiro Nome',

            'last_name' => 'Último Nome',

            'date_born' => 'Data de Nascimento',

            'picture' => 'Avatar',

            'sex' => 'Gênero',

            'description' => 'Descrição',

            'facebook' => 'Facebook',

            'twitter' => 'Twitter',

            'date_register' => 'Date Register',

            'receive_email' => 'Receive Email',

            'date_last_edit' => 'Date Last Edit',

            'edit_count' => 'Edit Count',

            'last_time_logged_in' => 'Last Time Logged In',

        );

    }


    /**

     * Retrieves a list of models based on the current search/filter conditions.

     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.

     */

    public function search() {

        // Warning: Please modify the following code to remove attributes that

        // should not be searched.


        $criteria = new CDbCriteria;


        $criteria->compare('id', $this->id);

        $criteria->compare('username', $this->username, true);

        $criteria->compare('password', $this->password, true);

        $criteria->compare('email', $this->email, true);

        $criteria->compare('first_name', $this->first_name, true);

        $criteria->compare('last_name', $this->last_name, true);

        $criteria->compare('date_born', $this->date_born, true);

        $criteria->compare('picture', $this->picture, true);

        $criteria->compare('sex', $this->sex, true);

        $criteria->compare('description', $this->description, true);

        $criteria->compare('facebook', $this->facebook, true);

        $criteria->compare('twitter', $this->twitter, true);

        $criteria->compare('date_register', $this->date_register, true);

        $criteria->compare('receive_email', $this->receive_email);

        $criteria->compare('date_last_edit', $this->date_last_edit, true);

        $criteria->compare('edit_count', $this->edit_count);

        $criteria->compare('last_time_logged_in', $this->last_time_logged_in, true);


        return new CActiveDataProvider($this, array(

                    'criteria' => $criteria,

                ));

    }


    /**

     * @return date_born formated as DD/MM/YYYY

     */

    public function getDateBorn() {

        $date_array = explode('-', $this->date_born);

        return $date_array[2] . '/' . $date_array[1] . '/' . $date_array[0];

    }


    public function beforeSave() {

        if (parent::beforeSave()) {

            if ($this->isNewRecord) {

                //In case its a new User

                $password = md5($this->password);

                $date_array = explode('/', $this->date_born);


                $this->password = $password;

                $this->date_born = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0];

            } else {

                //In case we're editing a User

                $this->edit_count++;

                $this->date_last_edit = new CDbExpression('NOW()');

            }

            return true;

        }

        return false;

    }


}



Como vocês podem ver eu tenho implementada uma função beforeSave() pra lidar com o formato das informações. Minha actionCreate do UsersController não funciona com essa função. Se eu apagar a função e lidar com esse formato na action, funciona normal. Sabem o que pode ser?

Thanks!

Tenta usar assim:




public function beforeSave() {

	

	if ($this->isNewRecord) {

		//In case its a new User

		$password = md5($this->password);

		$date_array = explode('/', $this->date_born);


		$this->password = $password;

		$this->date_born = $date_array[2] . '-' . $date_array[1] . '-' . $date_array[0];

	} else {

		//In case we're editing a User

		$this->edit_count++;

		$this->date_last_edit = new CDbExpression('NOW()');

	}

	return parent::beforeSave()

	

}