本文整理汇总了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');
}
示例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']);
}
示例3: __construct
public function __construct()
{
parent::__construct();
// Add validation rules here.
}
示例4: __construct
/**
* Constructor.
*/
public function __construct()
{
parent::__construct();
$this->_useI18n = true;
}
示例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']))]]);
}
示例6: __construct
/**
* ConfigValidator constructor.
*/
public function __construct()
{
parent::__construct();
$this->add('expire', ['numeric' => ['rule' => ['numeric'], 'message' => __d('cookie_warning', 'Valeur non reconnue')]]);
}