本文整理汇总了PHP中CValidator类的典型用法代码示例。如果您正苦于以下问题:PHP CValidator类的具体用法?PHP CValidator怎么用?PHP CValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CValidator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: validateConditional
/**
*
* @param CModel $object the object to be validated
* @param mixed $rule the rules to validate the object against
* @return boolean false if it has errors, true otherwise
*/
protected function validateConditional(&$object, $rule)
{
if (isset($rule['group'])) {
if (is_array($rule['group'])) {
foreach ($rule['group'] as $r) {
if (is_array($r)) {
$val = $this->validateConditional($object, $r);
if (!$val) {
return false;
}
} else {
continue;
}
}
} else {
throw new \CException(\Yii::t('EConditionalValidator', 'Group must be an array of rules'));
}
} else {
list($attributes, $conditionalValidator) = $rule;
$parameters = array_splice($rule, 2);
$validator = \CValidator::createValidator($conditionalValidator, $object, $attributes, $parameters);
$validator->validate($object);
if ($object->hasErrors()) {
$object->clearErrors();
return false;
}
}
return true;
}
开发者ID:nikel303,项目名称:yii_conditional_validator,代码行数:35,代码来源:Validator.php
示例2: beforeValidate
public function beforeValidate()
{
if (parent::beforeValidate()) {
$validator = CValidator::createValidator('unique', $this, 'district_name', array(
'criteria' => array(
'condition'=>'city_id=:city_id',
'params'=>array(
':city_id'=>$this->city_id
)
)
));
$validator2 = CValidator::createValidator('unique', $this, 'url', array(
'criteria' => array(
'condition'=>'city_id=:city_id',
'params'=>array(
':city_id'=>$this->city_id
)
)
));
$this->getValidatorList()->insertAt(0, $validator);
$this->getValidatorList()->insertAt(0, $validator2);
return true;
}
return false;
}
开发者ID:Aplay,项目名称:Fastreview_site,代码行数:27,代码来源:District.php
示例3: localConfigValueValidator
public function localConfigValueValidator($attribute, $params)
{
if ($this->type == self::TYPE_INT) {
$numericValidator = CValidator::createValidator('CNumberValidator', $this, $attribute, array('allowEmpty' => false, 'integerOnly' => true));
$numericValidator->validate($this);
}
}
开发者ID:DarkAiR,项目名称:test,代码行数:7,代码来源:LocalConfigItem.php
示例4: actionAdmin
public function actionAdmin($id)
{
$model = new ContestEntry();
$model->contest_id = $id;
if (!($contest = Contest::model()->findByPk($id))) {
throw new CHttpException(404);
}
$fieldsValidators = '';
$i = 0;
foreach (ContestField::model()->with(array('multi' => array('index' => 'id')))->findAllByAttributes(array('contest_id' => $id)) as $field) {
if ($field->result && $field->type != 'title') {
$this->fields[] = array('title' => $field->title, 'type' => $field->type, 'multi' => $field->multi, 'id' => $field->id);
$fieldsValidators .= 'field_' . $i . ', ';
if (isset($_GET['ContestEntry'])) {
$model->{'field_' . $i} = $_GET['ContestEntry']['field_' . $i];
}
$i++;
}
}
$model->fields = $this->fields;
$validators = $model->getValidatorList();
$validators->add(CValidator::createValidator('safe', $this, substr($fieldsValidators, 0, -2)));
if (isset($_GET['ContestEntry'])) {
$model->id = $_GET['ContestEntry']['id'];
$model->created_at = $_GET['ContestEntry']['created_at'];
}
$this->render('admin', array('model' => $model, 'contest' => $contest));
}
开发者ID:kostya1017,项目名称:our,代码行数:28,代码来源:AdminresultsController.php
示例5: validateAttribute
/**
* {@inheritDoc}
* @see CValidator::validateAttribute()
*/
public function validateAttribute($object, $attribute)
{
$array_to_validate = $object->{$attribute};
if (!is_array($array_to_validate)) {
$this->addError($object, $attribute, Yii::t('validator.array', 'The attribute "{attr}" is not an array.', array('{attr}' => $attribute)));
return;
}
if ($this->minElements !== null && count($array_to_validate) < $this->minElements) {
$this->addError($object, $attribute, Yii::t('validator.array', '{attribute} should contains at least {n} elements.', array('{n}' => $this->minElements)));
return;
}
if ($this->maxElements !== null && count($array_to_validate) > $this->maxElements) {
$this->addError($object, $attribute, Yii::t('validator.array', '{attribute} should contains at max {n} elements.', array('{n}' => $this->maxElements)));
return;
}
foreach ($this->rules as $rule) {
$name = $rule[0];
unset($rule[0]);
$validated_values = array();
// extract the values to validate from object
foreach ($array_to_validate as $key => $value) {
$object->{$attribute} = $value;
// for each value, set the attribute at this specific value
$validator = CValidator::createValidator($name, $object, array($attribute), $rule);
$validator->validate($object, array($attribute));
// get the validated values into another array
$validated_values[$key] = $object->{$attribute};
}
// set back the attribute array with the validated attributes
$object->{$attribute} = $validated_values;
}
}
开发者ID:yii1-extended,项目名称:yii1-array-validator,代码行数:36,代码来源:CArrayValidator.php
示例6: actionCreate
public function actionCreate()
{
$model = new AttendanceAbsences();
$modelPhoto = new ImportForm();
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if (isset($_POST['AttendanceAbsences'])) {
$model->attributes = $_POST['AttendanceAbsences'];
$modelPhoto->attributes = $_POST['ImportForm'];
$imgFile = CUploadedFile::getInstance($modelPhoto, 'file');
if ($_POST['command'] == 'save') {
$model->status = 'approved';
}
if ($model->doctor_note == 1) {
if (count($imgFile) == 0) {
$model->validatorList->add(CValidator::createValidator('letter_required', $model, 'doctor_letter_proof'));
}
}
if ($model->save()) {
if (count($imgFile) != 0) {
$imgFile->saveAs(letterPaths() . $model->id . '.jpg');
}
if ($_POST['command'] == 'save' && $model->type != 'Late') {
$model->savePresence();
}
$this->redirect(array('index'));
}
}
$this->render('create', array('model' => $model, 'modelPhoto' => $modelPhoto));
}
开发者ID:qhyabdoel,项目名称:hris_mujigae,代码行数:30,代码来源:AbsenceController.php
示例7: attach
public function attach($owner)
{
parent::attach($owner);
// Set up translatedAttributes.
foreach ($this->attributes as $attribute) {
foreach (Yii::app()->languageManager->suffixes as $suffix) {
$this->_translatedAttributes[] = $attribute . $suffix;
}
}
foreach ($this->_translatedAttributes as $varName) {
$this->{$varName} = null;
}
// Copying validation rules.
$rules = $owner->rules();
$validators = $owner->getValidatorList();
foreach (array_keys(Yii::app()->languageManager->languages) as $l) {
if ($l != Yii::app()->sourceLanguage) {
foreach ($this->attributes as $attr) {
foreach ($rules as $rule) {
$ruleAttributes = array_map('trim', explode(',', $rule[0]));
if (in_array($attr, $ruleAttributes)) {
$validators->add(CValidator::createValidator($rule[1], $this, $attr . '_' . $l, array_slice($rule, 2)));
}
}
}
}
}
}
开发者ID:kostya1017,项目名称:our,代码行数:28,代码来源:MultilangVirtualAttributesBehavior.php
示例8: myCaptcha
public function myCaptcha($attr, $params)
{
if (Yii::app()->request->isAjaxRequest) {
return;
}
CValidator::createValidator('captcha', $this, $attr, $params)->validate($this);
}
开发者ID:buildshop,项目名称:bs-common,代码行数:7,代码来源:ContactForm.php
示例9: linkUnique
/**
* Проверка ссылки на уникальность
*
* @param string $attribute
* @param array $params
*/
public function linkUnique($attribute, $params = array())
{
if (!$this->hasErrors()) {
$params['criteria'] = array('condition' => 'link = :link AND gs_id = :gs_id', 'params' => array('link' => $this->link, 'gs_id' => $this->gs_id));
$validator = CValidator::createValidator('unique', $this, $attribute, $params);
$validator->validate($this, array($attribute));
}
}
开发者ID:mmorpg2015,项目名称:ghtweb5,代码行数:14,代码来源:ShopCategories.php
示例10: files
public function files($attribute, $params)
{
$validator = CValidator::createValidator('file', $this, $attribute, $params);
foreach (CUploadedFile::getInstances($this, $attribute) as $file) {
$this->{$attribute} = $file;
$validator->validate($this, $attribute);
}
}
开发者ID:Gameonn,项目名称:JS_API,代码行数:8,代码来源:Reward.php
示例11: attach
public function attach($owner)
{
$validators = $owner->getValidatorList();
foreach ($this->rules() as $rule) {
$validators->add(CValidator::createValidator($rule[1], $owner, $rule[0], array_slice($rule, 2)));
}
parent::attach($owner);
}
开发者ID:nellka,项目名称:mebel,代码行数:8,代码来源:SEOBehavior.php
示例12: uniqueLogin
public function uniqueLogin($attribute, $params = array())
{
if (!$this->hasErrors()) {
$params['criteria'] = array('condition' => 'login=:login', 'params' => array(':login' => $this->login));
$validator = CValidator::createValidator('unique', $this, $attribute, $params);
$validator->validate($this, array($attribute));
}
}
开发者ID:seekermain,项目名称:forms,代码行数:8,代码来源:User.php
示例13: attach
public function attach($owner)
{
parent::attach($owner);
if (in_array($owner->scenario, $this->scenarios)) {
// добавляем валидатор файла
$fileValidator = CValidator::createValidator('file', $owner, $this->attributeName, array('types' => $this->fileTypes, 'allowEmpty' => true));
$owner->validatorList->add($fileValidator);
}
}
开发者ID:resoul,项目名称:simicom_com_ua,代码行数:9,代码来源:UploadableFileBehavior.php
示例14: attach
/**
* Создание валидатора для загружаемого изображения
*/
public function attach($owner)
{
parent::attach($owner);
$this->simpleImage = Yii::app()->simpleImage;
if (in_array($owner->scenario, $this->scenarios)) {
$fileValidator = CValidator::createValidator('FileValidator', $owner, $this->attributeName, array('safe' => false, 'enableClientValidation' => true, 'allowEmpty' => true, 'maxSize' => $this->maxSize, 'types' => $this->fileTypes, 'mimeTypes' => $this->mimeTypes, 'tooLarge' => Yii::t('yii', 'Размер файла "{file}" слишком велик, он не должен превышать {limit}.')));
$owner->validatorList->add($fileValidator);
}
}
开发者ID:Wiedzal,项目名称:narisuemvse,代码行数:12,代码来源:ImageBehavior.php
示例15: init
public function init()
{
parent::init();
if ($this->isInt()) {
$this->model->addValidator(CValidator::createValidator('numerical', $this->model, $this->attributeName, array('on' => 'backendInsert, backendUpdate')));
} else {
$this->model->addValidator(CValidator::createValidator('length', $this->model, $this->attributeName, array('on' => 'backendInsert, backendUpdate', 'max' => 255)));
}
}
开发者ID:Cranky4,项目名称:npfs,代码行数:9,代码来源:TextFieldWidget.php
示例16: checkType
/**
* Checks the transport type.
* This is the 'checkType' validator as declared in rules().
*/
public function checkType($attribute, $params)
{
if ($this->type == 'smtp') {
$requireValidator = CValidator::createValidator('required', $this, 'host, username, password');
$requireValidator->validate($this);
$emailValidator = CValidator::createValidator('email', $this, 'username');
$emailValidator->validate($this);
}
}
开发者ID:rash012,项目名称:cms,代码行数:13,代码来源:CallbackConfig.php
示例17: init
public function init()
{
parent::init();
$cs = Yii::app()->clientScript;
$cs->registerScriptFile(CHtml::asset(dirname(__FILE__) . '/../assets/BackendUploadedFiles.js'));
if ($this->getObjectParameter()->isRequired()) {
$this->model->getValidatorList()->add(CValidator::createValidator('required', $this->model, array($this->getObjectParameter()->getFieldName()), array('on' => 'backendInsert, backendUpdate')));
}
}
开发者ID:kot-ezhva,项目名称:ygin,代码行数:9,代码来源:SingleFileUploadWidget.php
示例18: validateValue
public function validateValue()
{
if (parent::validateValue()) {
$validator = CValidator::createValidator('type', $this, 'value', array('type' => 'integer'));
$validator->allowEmpty = false;
$validator->validate($this);
return !$this->hasErrors();
}
return false;
}
开发者ID:maruthisivaprasad,项目名称:zurmo,代码行数:10,代码来源:MarketingListWorkflowActionAttributeForm.php
示例19: beforeValidate
/**
* Anchor or title requires title field.
*/
public function beforeValidate($event)
{
$owner = $this->getOwner();
$this->_validatorIndexes = array();
if ($this->title_anchor || $this->title_page) {
foreach (Yii::app()->languageManager->suffixes as $suffix) {
$this->_validatorIndexes[] = $this->_validators->add(CValidator::createValidator('required', $owner, 'title' . $suffix));
}
}
$this->_validatorIndexes = array_reverse($this->_validatorIndexes);
}
开发者ID:kostya1017,项目名称:our,代码行数:14,代码来源:BlocBehavior.php
示例20: beforeValidate
public function beforeValidate()
{
if (!$this->isNewRecord) {
$this->_storedPassword = self::model()->findByPk($this->id)->password;
}
if ($this->isNewRecord && $this->password == '') {
$validators = $this->getValidatorList();
$validators->add(CValidator::createValidator('required', $this, 'password'));
}
return parent::beforeValidate();
}
开发者ID:kostya1017,项目名称:our,代码行数:11,代码来源:Member.php
注:本文中的CValidator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论