Validation twice in MVC implementation.


(Jinxi Cheng) #1

Hi,

I am writing a YII application. For the sign up process I have two models written: User, SignupForm.

In my User model I have a list of rules defined e.g. the email attribute must be validated as an email. The same attribute I have it defined in SignupForm also.

I have the feeling that I am doing it wrong, since my codes is now doing the field validation twice, namely in the User object and in the SignupForm model.

Can some one shed some light on this matter? Thank you in advance.


(Alexander Makarov) #2

If you’re absolutely sure that data provided by SignupForm is OK, you can pass false to user’s save method to skip validation.


(Alexander Makarov) #3

Duplicating rules is OK in this case. They are similar but not the same.