Yii Framework Forum: Validation twice in MVC implementation. - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Validation twice in MVC implementation.

#1 User is offline   ginbuntu 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 08-May 14

  Posted 21 March 2017 - 04:52 PM

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.
0

#2 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 22 March 2017 - 11:11 AM

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

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#3 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,184
  • Joined: 17-January 09
  • Location:Russia

Posted 22 March 2017 - 11:11 AM

Duplicating rules is OK in this case. They are similar but not the same.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users