[Solved] Perplexing Error, Model Won't Save?

[solved] very basic, forgot to return true on beforeSave()

Hi all,

I have a model which controls the accounts table in my database, I am trying to add a new row from a form, however when saving the model with the below code, nothing happens! I get no PHP log errors, no Yii log entries at all, no model validation errors and no Apache errors. Is there something anyone can see that would cause this model to fail saving?

Note: "…" in place of actual code to keep things short

Model:




class Account extends CActiveRecord

{

	public $password_confirm;

	 

	/**

	 * Returns the static model of the specified AR class.

	 * @param string $className active record class name.

	 * @return Account 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 'account';

	}


	/**

	 * @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('first_name, last_name, address_1, city, state, post_code, country, email', 'required'),

			array('password, password_confirm', 'required', 'on'=>'register'),

			array('birthday_time, create_time, login_time, is_active, auth_id', 'numerical', 'integerOnly'=>true),

			array('first_name, last_name, email, phone_number, address_1, address_2, state, country, website', 'length', 'max'=>255),

			array('post_code', 'length', 'max'=>7),

			array('password, salt', 'length', 'max'=>32),

			array('notes, edit, submit', 'safe'),

			array('phone_number', 'phoneValidator'),

			array('email', 'emailValidator'),

			array('password', 'compare', 'compareAttribute'=>'password_confirm', 'on'=>'update'),

			array('password_confirm, id', 'safe'),

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

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

			array('id, first_name, last_name, email, phone_number, address_1, address_2, state, country, post_code, website, birthday_time, password, salt, create_time, login_time, is_active, auth_id, notes', 'safe', 'on'=>'search'),

		);

	}


	/**

	 * @return array relational rules.

	 */

	public function relations()

	{

		...

	}


	/**

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

	 */

	public function attributeLabels()

	{

		...

	}


	/**

	 * 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()

	{

		...

	}

	

	public function beforeSave() {

		//new

		if($this->isNewRecord) {

			//generate password and encrypt and send email

			$hasher = new PasswordHash();

			$hash = $hasher->create_hash($this->password);

			list($type, $itterations, $password, $salt) = explode(':', $hash);

			

			$this->password = $password;

			$this->salt = $salt;

			$this->create_time = time();

			$this->is_active = 1;

			$this->auth_id = 0;

		}

....

...

...


//checks if email is unique if not logged in

	public function emailValidator($attribute) {

		$results = Yii::app()->db->createCommand()

					->select('a.*')

					->from('account a')

					->where('a.email = :email', array(':email' => $this->$attribute))

					->queryAll();

					

		if(count($results) > 0 && $_POST['edit'] == 0 && $this->isNewRecord) {

			$this->addError($attribute, 'Email is already in use!');

		}

		else {

			return;

		}

	}

	

	//phone validator

	public function phoneValidator($attribute) {

		if(!preg_match('/^[+]?([\d]{0,3})?[\(\.\-\s]?([\d]{3})[\)\.\-\s]*([\d]{3})[\.\-\s]?([\d]{4})$/', $this->$attribute)) {

			$this->addError($attribute, 'Phone number is not valid!');

		}

		else {

			return;

		}

	}



Controler Action:




public function actionAdd() {

		if(isset($_POST['submit'])) {

			$account_model = new Account();

			$hasher = new PasswordHash();

			$emailer = new Emails();

			

			//auto gen a password and copy to model validation

			$_POST['password'] = $hasher->passwordGenerate();

			$_POST['password_confirm'] = $_POST['password'];

			unset($_POST['submit']);

			

			$account_model->attributes = $_POST;

			

			if($account_model->save()) {

				//send email to user about new account

				$emailer->newAccount($account_model->id, $_POST['password']);

				

				Yii::app()->user->setFlash('success', 'Client was created and an email has been sent to them with their account information!');

				$this->redirect('edit?id=' . $account_model->id .'');

			}

			else {

				Yii::app()->user->setFlash('error', 'There was an error in your input, please read the errores bellow and try again.');

			}

		}

		

		$this->render('add', array('model' => $account_model));

	}



Thanks for your help

edit: spelling