當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。