How Can I Use Rules & Scenario In Professional Way In My Projects ?

Hi

In my project i am using Gii to generate my model.Here by default i am getting some rues depends on my

database table structure.

But I am facing so many validation problem because of this default rules.

For example i have one sign up form and i am using user model…there i need almost all fields as mandatory… same time i have some other forms like change password, or update profile etc… but here I am using some few fields as mandatory.

If i write a scenario for these forms also while submitting the form which validating those fields which i am not using this forms why because the default rules.Here Please advise me how i can handle this problem like a professional way…

Hi,

you can use something looklike this


return array(

		// name, email, subject and body are required

		array('email,username,first-name,last-name', 'required','on'=>'create'),

                array('change password,password', 'required','on'=>'update'),

		array('email', 'email'),

		array('zipcode,phone_number', 'numerical'),

		array('password', 'required', 'on'=>'update'),

		array('password_repeat', 'compare', 'compareAttribute'=>'password', 'on'=>'update'),


		);

you can use this

insert time…


$model = new Users('create');

and record update


$model = new Users('update');

more reference please see it…

http://www.yiiframework.com/doc/guide/1.1/en/form.model

i hope it’s works…

thanks for your quick response…

the same way i done but apart from that i kept the default rules which Gii provided.

So maybe there i did the mistake.Please correct me if i wrong…