当前位置: 首页>>代码示例>>PHP>>正文


PHP Validator::__construct方法代码示例

本文整理汇总了PHP中Cake\Validation\Validator::__construct方法的典型用法代码示例。如果您正苦于以下问题:PHP Validator::__construct方法的具体用法?PHP Validator::__construct怎么用?PHP Validator::__construct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Cake\Validation\Validator的用法示例。


在下文中一共展示了Validator::__construct方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 /**
  * Construct.
  *
  * Adds some default validation rules.
  * @uses Cake\Validation\Validator::__construct()
  */
 public function __construct()
 {
     parent::__construct();
     //ID
     $this->add('id', 'valid', ['rule' => 'naturalNumber'])->allowEmpty('id', 'create');
     //User (author)
     $this->add('user_id', ['naturalNumber' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'naturalNumber']]);
     //Email
     $this->add('email', ['email' => ['message' => __d('me_cms', 'You have to enter a valid value'), 'rule' => 'email'], 'lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]]]);
     //First name
     $this->add('first_name', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 40), 'rule' => ['lengthBetween', 3, 40]], 'personName' => ['message' => sprintf('%s: %s. %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'letters, apostrophe, space'), __d('me_cms', 'Has to begin with a capital letter')), 'rule' => [$this, 'personName']]]);
     //Last name
     $this->add('last_name', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 40), 'rule' => ['lengthBetween', 3, 40]], 'personName' => ['message' => sprintf('%s: %s. %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'letters, apostrophe, space'), __d('me_cms', 'Has to begin with a capital letter')), 'rule' => [$this, 'personName']]]);
     //Title
     $this->add('title', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]], 'validateUnique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']]);
     //Filename
     $this->add('filename', ['blank' => ['message' => __d('me_cms', 'Can not be changed'), 'on' => 'update', 'rule' => 'blank'], 'maxLength' => ['message' => __d('me_cms', 'Must be at most {0} chars', 255), 'rule' => ['maxLength', 255]], 'validateUnique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']]);
     //Subtitle
     $this->add('subtitle', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 150), 'rule' => ['lengthBetween', 3, 150]]])->allowEmpty('subtitle');
     //Slug
     $this->add('slug', ['lengthBetween' => ['message' => __d('me_cms', 'Must be between {0} and {1} chars', 3, 100), 'rule' => ['lengthBetween', 3, 100]], 'slug' => ['message' => sprintf('%s: %s', __d('me_cms', 'Allowed chars'), __d('me_cms', 'lowercase letters, numbers, dash')), 'rule' => [$this, 'slug']], 'validateUnique' => ['message' => __d('me_cms', 'This value is already used'), 'provider' => 'table', 'rule' => 'validateUnique']]);
     //Text
     $this->notEmpty('text', __d('me_cms', 'This field can not be empty'));
     //Priority
     $this->add('priority', ['range' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => ['range', 1, 5]]]);
     //Description
     $this->add('description', ['maxLength' => ['message' => __d('me_cms', 'Must be at most {0} chars', 255), 'rule' => ['maxLength', 255]]])->allowEmpty('description');
     //Active
     $this->add('active', ['boolean' => ['message' => __d('me_cms', 'You have to select a valid option'), 'rule' => 'boolean']]);
     //Created
     $this->add('created', ['datetime' => ['message' => __d('me_cms', 'You have to enter a valid value'), 'rule' => 'datetime']])->allowEmpty('created');
 }
开发者ID:mirko-pagliai,项目名称:me-cms,代码行数:38,代码来源:AppValidator.php

示例2: __construct

 public function __construct()
 {
     parent::__construct();
     $usersTable = TableRegistry::get('Users');
     $this->requirePresence('username', 'create')->requirePresence('password', 'create')->requirePresence('first_name', 'create')->requirePresence('last_name', 'create');
     if (Configure::read('Users.use_email_as_username')) {
         $this->add('username', 'validFormat', ['rule' => 'email', 'message' => __('Must be a valid email address.')]);
     } else {
         $this->requirePresence('email', 'create')->add('email', 'validFormat', ['rule' => 'email', 'message' => __('Must be a valid email address.')]);
     }
     $this->add('confirm_password', 'compare', ['rule' => ['compareWith', 'password'], 'message' => __('Passwords do not match.')]);
     $this->add('username', 'unique', ['rule' => function ($value, $context) use($usersTable) {
         $user = $usersTable->findByUsername($value);
         return $user->count() > 0 ? false : true;
     }, 'message' => __('This username is already in use.'), 'on' => 'create'])->add('email', 'unique', ['rule' => function ($value, $context) use($usersTable) {
         $user = $usersTable->findByEmail($value);
         return $user->count() > 0 ? false : true;
     }, 'message' => __('This email is already in use.'), 'on' => 'create']);
 }
开发者ID:propellerstudios,项目名称:users-plugin,代码行数:19,代码来源:UsersValidator.php

示例3: __construct

 public function __construct()
 {
     parent::__construct();
     // Add validation rules here.
 }
开发者ID:grandfelix,项目名称:woodyattachments,代码行数:5,代码来源:FileuploadValidator.php

示例4: __construct

 /**
  * Constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->_useI18n = true;
 }
开发者ID:neojoda,项目名称:cakephp-i18n,代码行数:8,代码来源:Validator.php

示例5: __construct

 /**
  * Constructor
  *
  * @return void
  */
 public function __construct()
 {
     parent::__construct();
     $this->add('lang', ['inLangList' => ['rule' => ['inList', $this->validList['lang']], 'message' => __d('recaptcha', 'The lang should be in the following authorized lang ' . implode(',', $this->validList['lang']))]])->add('theme', ['inThemeList' => ['rule' => ['inList', $this->validList['theme']], 'message' => __d('recaptcha', 'The theme should be in the following authorized theme ' . implode(',', $this->validList['theme']))]])->add('type', ['inTypeList' => ['rule' => ['inList', $this->validList['type']], 'message' => __d('recaptcha', 'The type should be in the following authorized type ' . implode(',', $this->validList['type']))]])->add('size', ['inSizeList' => ['rule' => ['inList', $this->validList['size']], 'message' => __d('recaptcha', 'The size should be in the following authorized type ' . implode(',', $this->validList['size']))]]);
 }
开发者ID:cakephp-fr,项目名称:recaptcha,代码行数:10,代码来源:GlobalValidator.php

示例6: __construct

 /**
  * ConfigValidator constructor.
  */
 public function __construct()
 {
     parent::__construct();
     $this->add('expire', ['numeric' => ['rule' => ['numeric'], 'message' => __d('cookie_warning', 'Valeur non reconnue')]]);
 }
开发者ID:cakephp-fr,项目名称:cookie-warning,代码行数:8,代码来源:ConfigValidator.php


注:本文中的Cake\Validation\Validator::__construct方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。