Using the 'on'=>'scenario' option

Hi,

I want to implement the 'on'=>'scenario' way of defining a rule. I've defined the rules thus:



array('PASSWORD, PASSWORD_REPEAT, EMAIL', 'required', 'on'=>'create'), 


   			array('PASSWORD','length','max'=>32),


   			array('EMAIL','length','max'=>30),


   			array('EMAIL', 'unique', 'on'=>'create'),


   			array('PASSWORD_REPEAT','length','max'=>32),


   			array('PASSWORD', 'compare', 'compareAttribute'=>'PASSWORD_REPEAT', 'on'=>'create'),


My real problem comes from the fact that this form is not used independently, but is used respectively in the views of userFirms and userPersons.

This is the validation and save code:



	$users->attributes = $_POST['users'];


		$users->USER_ID                 =     $UserID;


		$users->PASSWORD_REPEAT         =     $_POST['users']['PASSWORD_REPEAT'];





		$users->TYPE                    =     "2";





		$userpersons->attributes = $_POST['userPersons'];


		$userpersons->USER_ID  	        = $UserID;





		$result1 = $users->validate();


		$result2 = $userpersons->validate();


The action is called "create", but it is an active from the userPersons controller, not from users. Therefore, defining the rules with 'on'=>'create" in users model doesn't make sense as I don't call them in the create Action in the users controller, but in the create action in the userPersons controller.

Which is the best approach to solve my problem?

Thanks in advance.

The scenario name has nothing to do with action name. It is passed as a parameter to the validate() method.

http://php-thoughts…tion-scenarios/

Thanks guys! I understood that I was in mistake.