Problem With Custom Unique Validation Method

I have added two virtual properties to my model …

$isSystemUser and $username.

These properties are both public.

I have also added them into my normal rule validations as "safe".

I have this code to validate that a username is unique when a checkbox is checked. This code is absolutely fine and should work.




public function uniqueWhenIsSystemUserChecked($attribute, $params) {

						

	if($this->isSystemUser && $this->username != null) {

								

		$uniqueValidator = new CUniqueValidator;

		$uniqueValidator->attributeName = "UserName";

		$uniqueValidator->className = "Person";

		$uniqueValidator->validate($this, "username");

				

	}

			

}



The problem is when I run this code. It has not put the two virtual properties in the attributes of the model, do you have any ideas why? So when I run the validate() method it thinks the two virtual properties do not exist.

How do I get my virtual properties to show up in the attributes and work like normal attributes?

Please note: I have done $model->attributes = $_POST["Model"]; in the controller so that is all setup and should work.

in your controller when you do this


$model->attributes = $_POST["Model"];

dump the attributes immediately and see if the values are there


var_dump($model->attributes);