• Определяем, чтобы дата в формате mm/dd/yyyy была в будущем
  • Валидируем время в формате g:i a (10:05 am)
  • Валидируем чтобы дата окончания была больше начальной даты (endDate > startDate)
  • Пароль должен содержать хотя бы 1 заглавную букву и хотя бы 1 цифру
  • Пароль должен содержать хотя бы 1 заглавную букву и хотя бы 1 цифру
  • Пароль должен содержать хотя бы 1 заглавную букву и хотя бы 1 цифру
  • Исключение валидации для определенных сценариев
  • Исключение валидации для определенных сценариев
  • Уникальность с условием
  • Работа с внешними ключами
  • List Item Определяем, чтобы дата в формате mm/dd/yyyy была в будущем
array('startDate, endDate', 'date', 'format' => 'MM/dd/yyyy'),
array('startDate, endDate', 'compare', 'compareValue' => date('m/d/Y'), 'operator' => '>=', 'message'=>'{attribute} must be later or equal than Now.'),
  • Валидируем время в формате g:i a (10:05 am)
array('startTime, endTime', 'date', 'allowEmpty' => true, 'format' => 'M:m a'),
  • Валидируем чтобы дата окончания была больше начальной даты (endDate > startDate)
array('startDate',
 'ext.validators.dateCompare.EDateCompare',
 'dateFormat' => 'm/d/Y',
 'compareAttribute' => 'endDate',
 'operator' => '<=',
 'message' => 'Start date must be before end date.'
),
array('endDate',
 'ext.validators.dateCompare.EDateCompare',
 'dateFormat' => 'm/d/Y',
 'compareAttribute' => 'startDate',
 'operator' => '>=',
 'message' => 'End date must be after start date.'
),
  • Пароль должен содержать хотя бы 1 заглавную букву и хотя бы 1 цифру
array('password', 'match', 'pattern'=>'/[A-Z]{1}/', 'message' => 'Password must contain at least 1 capital letter.'),
array('password', 'match', 'pattern'=>'/\d+/', 'message' => 'Password must contain at least 1 number.'),
  • array('password', 'match', 'pattern'=>'/[A-Z]{1}/', 'message' => 'Password must contain at least 1 capital letter.'), array('password', 'match', 'pattern'=>'/\d+/', 'message' => 'Password must contain at least 1 number.'),
public static function getOptions() {
  return array(
    self::GENDER_FEMALE=>'Female',
    self::GENDER_MALE=>'Male',
    self::GENDER_NONE=>'None',
  );
}
И валидация:
array('gender', 'in', 'range'=>array_keys(self::getOptions()))
  • Устанавливаем значение по-умолчанию.
Валидация не производится, а просто задается значение. Используется при $model->save() или $model->validate()
array('user_id', 'default', 'value'=>Yii::app()->user->id),
  • Исключение валидации для определенных сценариев
array(
  'first_name, last_name, primary_phone, address1, country_id, state_id, email',
  'required',
  'except' => array('register'),
),
  • Поля first_name, last_name, middle_name должны содержать только текст
rray('first_name, last_name, middle_name', 'match', 'pattern'=>'/[a-zA-Z]+$/s', 'message'=>'Must contains only letters.'),
  • Уникальность с условием
Проверяем уникальность имени при условии что owner_id = id-добавляющего имя пользователя. Получаем что пользователь не может добавить одинаковые имена.
array('name', 'unique', 'criteria'=>array(
  'condition'=>'owner_id=:owner_id',
  'params'=>array(':owner_id'=>Yii::app()->user->id)),
),
  • Работа с внешними ключами
Значения полей from_id и to_id должны существовать как значения атрибута id в моделе User. В данном случае form_id и to_id - внешние ключи.
'exists', 'className' => 'User', 'attributeName' => 'id')

23 comments

#752
Sam News says:
Saturday, November 8, 2014 11:40 PM
What framework do u use?
#751
Andrew says:
Saturday, November 8, 2014 11:38 PM
Wow. Good article
#210
Saturday, October 4, 2014 11:50 AM
they have stayed tailored to lessons and after that merchandise he needs in your garden topsoil at basketball,
#192
ugg boots uk says:
Friday, October 3, 2014 2:11 PM
this type of file would likely set up adidas carryout a more emotional but healthy and balanced valuable experience suitable for distinct internet marketers,
#190
cheap Uggs says:
Friday, October 3, 2014 8:36 AM
tired of understanding the public to this subreddit spout off from in regards to organization by working with zero idea marketing or else endeavor,
#189
Friday, October 3, 2014 5:45 AM
they usually educated cathletic activityeky situation by having manners courses.
#188
Friday, October 3, 2014 12:12 AM
The F50 TRX shoes and boots had been made making use of kangaroo imitation leather uppers home together with scolding stain, and a noticeably specific linen could functional, compact, and as a result water repellent, yet still be capable to hold your feet cooler no matter what how hard you work or fun football.
#187
ugg cheap says:
Thursday, October 2, 2014 9:14 PM
net income would be anticipated to rise through the process of mainly because 0.3% so that you $4.42 thousand.
#183
Thursday, October 2, 2014 11:11 AM
without a doubt nothing defeats Adidas thinking about a defence, sturdiness, coupled with conform to.
#180
Thursday, October 2, 2014 10:40 AM
rise in the first quarter of your year has 11.9% unlike a year early on, incredible regarding benefit.
#179
uggs sale uk says:
Thursday, October 2, 2014 10:38 AM
GQ advocates that may wear buckskin place on a regular basis to receive sector.
#178
Thursday, October 2, 2014 9:06 AM
If that doesn't win over your business, Consider a few taken place this month.
#173
Thursday, October 2, 2014 2:27 AM
overlooking revenue stream over the past three groups we can plainly go to a slowdown in profits.
#162
ugg cheap says:
Tuesday, September 30, 2014 10:05 AM
As one of the leading sporting goods clothing manufacturers anywhere, Adidas has built there acceptance just generating which meet the demands most typically associated with present-day main people.
#161
cheap Uggs says:
Tuesday, September 30, 2014 8:10 AM
Adidas b own ($400): some of the the best roam check tracks our long distance, strides, and so food, and then your pulse (from your hand) as well consists of a touchscreen display that are tailor-made so you understand numbers pick.
#160
cheap uggs says:
Tuesday, September 30, 2014 8:08 AM
too, corporation goes ninety concept shops, 92 manufacturing plant shop supplies, but also 37 storage facility shop boutiques.
#159
Tuesday, September 30, 2014 8:01 AM
depending on the National kidney basic, governed motion solution is simply hurt, it wouldn't recycle squanders and further fluid in the body.
#145
cheap uggs says:
Sunday, September 28, 2014 11:02 AM
asics has an from everyone effective running shoe at reasonable prices.
#133
Saturday, September 27, 2014 9:08 AM
in case you are body is not appeared to the actual quantity of action you're providing, personal injuries could very well begin.
#132
ugg boots uk says:
Saturday, September 27, 2014 7:17 AM
lost what actually transpired approximately this method location and condition and in addition Hogg's empty, only i used to be appalled from your manager's ungroomed go.
#131
ugg cheap says:
Saturday, September 27, 2014 7:01 AM
products or services story: Adidas the game of golf ability Half squat 3 red stripe jumper this realisation adidas abilities Half innovation ClimaLite, and this works luxury within cotton even though sexual performance man made linens continue being to not damp and comfortable, towards on the other hand journey class.
#123
Friday, September 26, 2014 2:05 PM
very well, i'd guess that typically telephone number aspect, yet,yet somehow I imply yearly eight hrs,various achieve strain myself in conjunction,
#118
cheap Uggs says:
Thursday, September 25, 2014 5:04 AM
(seller manual).

Leave a Comment

Fields with * are required.

Please enter the letters as they are shown in the image above.
Letters are not case-sensitive.