Yii Framework Forum: Validation Rules Example - Yii Framework Forum

Jump to content

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

Validation Rules Example

#1 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,697
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 22 November 2013 - 10:56 AM

Somebody please give me an example of how to write good validation rules and scenarios

Let's consider this table:

id - primary key, set by db
parent_id - foreign key, set by form
owner_id - foreign key, set by script, w/o form
field_1, field_2, ..., field_n - some data, required, set by form
another_field_1, another_field_2, ..., another_field_n - some data, can be empty/null, set by form
is_disabled - active flag, set by form during administration process



and these scenarios: update by user, update by admin, delete.
God is real unless declared as integer
0

#2 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,697
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 22 November 2013 - 11:05 AM

In this table example some fields (field_1 .. field_n, another_field_1 .. another_field_n) require strong validation (required, trim, strip_tags), some probably should also be validated (parent_id, owner_id - integer), and some must be assigned only in several scenarios (is_disabled - only for admin)

And we cannot use 'default' scenario here.

So when I've tried to write all these rules, my code became bulky. Any chance to do it in a couple of lines?..
God is real unless declared as integer
0

#3 User is offline   ORey 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,697
  • Joined: 20-April 09
  • Location:Moscow, Russia

Posted 24 November 2013 - 08:18 AM

Btw here's the answer I was looking for.
God is real unless declared as integer
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