Massive Assignment Non-Database Column Fields In Model

I have a CActiveRecord model, Job which has a public property $completionChoice.

It doesn’t relate to a databasefield, and I don’t have getter or setter methods for it. I use it as a flag for some processing during beforeSave()

What I’d like to be able to do is massively assign from the form, so have $_POST[‘completionChoice’] automatically get assigned to it when I do $job->attributes() = $_POST[‘Job’], however I can’t get it working.

I’ve tried setting $completionChoice as safe, and I’ve tried overriding CActiveRecord::attributeNames() to add it, but it doesn’t get assigned.

How do I do this?

Thanks

Iain

Dear Friend

I have a Model User.

I have a public property.




public $native="India";



I have made it safe during massive assignement.




array('native', 'safe'),



This is the controller logic.




public function actionCreate()

	{

		$model=new User;


		if(isset($_POST['User']))

		{  

                        $_POST['User']['native']="United States";

			$model->attributes=$_POST['User'];

			if($model->validate())

			    echo $model->native;


			/*if($model->save())

				$this->redirect(array('view','id'=>$model->id));*/

		}


		$this->render('create',array(

			'model'=>$model,

		));

	}



Now every time I submitting the form "United States" getting echoed.

Regards.

You’re quite right, it does work. The problem was with an error in another validation rule. I have fixed it now.

Thank you!

Iain