Virtual Attributes In Model Won't Bind

Hi guys,

Whenever I add a virtual attribute field to my model like so:




class User extends CActiveRecord

{

	public $title;



I can’t seem to bind the data in my update action in the controller:




public function actionUpdate($id)

	{

		$model = $this->loadModel($id);

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

		{

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


 			if($model->save())

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

		}


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

			'model'=>$model,

		));

	}



Then when I go look at what’s in $model->attributes i can’t find my $model->title anywhere.

It’s in the $_POST[‘User’], but for some reason it won’t bind to my model.

Anyone got any thoughts on how to troubleshoot this?

Thx in advance!

check whether the "title" is defined in the rules of the User model

Adding a max lenght did the trick, cheers.

Do I always have to define virtual fields in rules to make them show up in my data?

This holds true for all attributes: As long as they are not handled by a rule, they cannot be massively assigned. By the way: There’s the safe-validator for attributes that do not require any sort of validation ;)

There is also the 'unsafe’e validator that can be used to make an attribute unsafe.