$Model->Attributes Refuses To Set Property

I know there have been quite a few topic about this, but none of those helped me so bear with me.

I’m very new to Yii and making a simple application that allows a person to take a test. The participant enters some personal info on the first page, presses a button to start the test and gets a number of multiple-choice questions. Each question has it’s own page with a stateful form with a “next” button.

Simplified I have the following:



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


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

 * @property integer $id

 * @property integer $test

 * @property integer $question

 * @property integer $answer

 * @property integer $correct

 * @property integer $faulty

 * @property string $comment

 * @property integer $time_spent


 * The followings are the available model relations:

 * @property Question $question0

 * @property Answer $answer0

 * @property Test $test0


class TestAnswer extends CActiveRecord




	 * @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('test, question, answer, correct, faulty, comment, time_spent', 'required'),

			array('test, question, answer, correct, faulty, time_spent', 'numerical', 'integerOnly'=>true),

			array('comment', 'length', 'max'=>1500),





If I understand it correctly the fact that comment is mentioned in the rules means it’s a safe attribute.

Controller snippet





		$testAnswers = $this->getPageState("testAnswers", array());

		$testAnswer = new TestAnswer;

		$moreValues = end($testAnswers);

		echo "<br/>test3 | " . $moreValues['comment'] . "|";

		$testAnswer->attributes = $moreValues;

//		$testAnswer->setAttributes($moreValues, false);	

// 		$testAnswer->comment = $moreValues->comment;

		echo "<br/>test4 | " . $testAnswer->comment . "|";	


		$newTA = new TestAnswer;.

		$newTA->comment = 'blabla';

		array_push($testAnswers, $newTA);


		$this->setPageState("testAnswers", $testAnswers);






This is basically the part that handles the answer and sets up the next question. Test3 returns "blabla", but Test4 returns nothing

Can someone explain to me why the comment property on TestAnswer is not set by the following line?

$testAnswer->attributes = $moreValues;

Because of limitations on mass-assignment.

See docs, section for validation&

With all due respect, this doesn’t help me one bit. I obviously read the documentation and this specific article and from what i read I understand that what I do should work.

Could you maybe elaborate on this limitation you’re referring to?

And if this really is impossible to do how am I supposed to populate an object from the getPageState properly?

Ok, my bad.

Should work.

Check app logs for attributes assignment errors (if there’s something wrong, Yii complains)

If nothing’s there, I’d start to trace setAttributes function to see what’s going on.