how to configure the model based on existing ones

i have the user model and controller

but i m having an issue with them is that i want some user to update its account but all the fields are shown when i disable them the record is not saved, what i have done is that i created a separate controller for the update and define the rules for it in the separate model which extends user model

but still i cant save the model as it is requiring the verifycode and the confirm email (defined in the main user model)

inside user model:


array('first_name, last_name, password, email, dob, gender, email_confirm,verifyCode', 'required'),

inside the update model:


	array('first_name, last_name, email, dob, gender', 'required'),

p.s: i m using the user update view for the update model

any one here to help out?

When you need different rules for different scenarios (like update), you can specify the scenario in your rule set.

You can read more about scenario’s here: http://www.yiiframework.com/wiki/56/reference-model-rules-validation#hh3

thanks, this works but what if i have to use these fields in more than one scenarios will i pass array like this:


'on'=>array('signup','home')

when i do this then the fields in the view are not marked * and i want them to be * so that all fields are passed to model


array('password,email_confirm,verifyCode','required','on'=>'signup'),

You need to use labelEx() for displaying the ‘*’.

/Tommy

im using the labelEX

in the user model i have done this now




array('first_name, last_name, email, dob, gender, password,email_confirm,verifyCode', 'required', 'on'=>'signup'),

array('first_name, last_name, email, dob, gender', 'required', 'on'=>'update'),



but on signup view the fields are not marked as required and only captacha is validated

and on update all fields are marked required and it is also requiring the email_confirm and verifycode

on sign up i have ajax validation: but disabling it is also not working

what should i do

finally done it had to create separate controller for signup and separate model based on the user class, and done the update part inside the user class and defined update rules there.