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


PHP Model::validate方法代码示例

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


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

示例1: validate

 /**
  * Validate attribute & throw exception
  *
  * @param array $attributeNames
  * @param boolean $clearErrors
  * @param boolean $throwException
  * @return boolean
  * @throws ModelException
  */
 public function validate($attributeNames = null, $clearErrors = true, $throwException = true)
 {
     if (!parent::validate($attributeNames, $clearErrors) && $throwException) {
         throw new ModelException($this, Code::GENERAL_INVALID_USER_INPUT);
     }
     return !$this->hasErrors();
 }
开发者ID:weiyiyi,项目名称:base,代码行数:16,代码来源:Model.php

示例2: validate

 public function validate($attributeNames = null, $clearErrors = true)
 {
     $isValid = true;
     foreach ($this->models as $model) {
         $isValid = $model->validate($attributeNames, $clearErrors) && $isValid;
     }
     return parent::validate($attributeNames, $clearErrors) && $isValid;
 }
开发者ID:yinheark,项目名称:yincart2,代码行数:8,代码来源:FormModel.php

示例3: upload

 /**
  * Upload file
  *
  * @param Model $model
  * @param array $attributes - Model file type attributes
  * @param bool  $multiple
  *
  * @return array Attachment ID
  */
 public function upload($model = null, $attributes = null, $multiple = null)
 {
     $this->prepare($model, $attributes, $multiple);
     if ($this->model !== null && $this->attributes && $this->model->validate()) {
         foreach ($this->attributes as $attribute) {
             if ($this->model->{$attribute}) {
                 if (is_array($this->model->{$attribute})) {
                     foreach ($this->model->{$attribute} as $file) {
                         $ids[] = $this->uploadFile($file, $attribute);
                     }
                 } else {
                     $ids[] = $this->uploadFile($this->model->{$attribute}, $attribute);
                 }
             }
         }
     }
     return isset($ids) ? $ids : [];
 }
开发者ID:yiimediafile,项目名称:mediafile,代码行数:27,代码来源:MediaFile.php

示例4: validateAttributes

 /**
  * Валидация атрибутов.
  *
  * На вход передается модель для валидации и массив значений для валидации.
  * Массив значений должен иметь следующий формат:
  * ```php
  * array(
  *     '<attribute1>' => array(
  *         array(
  *             'value' => <mixed>, // значение для валидации
  *             'isValid' => <boolean>, // true, если значение должно проходить валидацию
  *         ),
  *     ),
  * )
  * ```
  *
  * Проверяет, что атрибут либо должен проходить проверку валидации, либо не должен.
  *
  * @param Model $model проверяемая модель
  * @param array $attributes массив значений атрибутов для валидации
  */
 protected function validateAttributes(Model $model, $attributes)
 {
     foreach ($attributes as $attribute => $values) {
         $attributeTitle = $model->getAttributeLabel($attribute);
         foreach ($values as $v) {
             $value = $v['value'];
             $isValid = $v['isValid'];
             $model->{$attribute} = $value;
             if ($isValid) {
                 $message = $attributeTitle . ' validation error: ' . implode("\n", $model->getErrors($attribute));
                 $message .= "\nAsserting value: " . print_r($value, true);
                 $this->assertTrue($model->validate([$attribute]), $message);
             } else {
                 $message = $attributeTitle . ' must be invalid' . "\n";
                 $message .= 'Asserting value: ' . print_r($value, true);
                 $this->assertFalse($model->validate([$attribute]), $message);
             }
         }
     }
 }
开发者ID:internet-design,项目名称:yii2-svk-tests,代码行数:41,代码来源:ModelTestTrait.php

示例5: readValue

 /**
  * @param Model $model
  * @param string $attribute
  */
 private function readValue($model, $attribute)
 {
     $model->{$attribute} = $this->prompt(mb_convert_case($attribute, MB_CASE_TITLE, 'utf-8') . ':', ['validator' => function ($input, &$error) use($model, $attribute) {
         $model->{$attribute} = $input;
         if ($model->validate([$attribute])) {
             return true;
         } else {
             $error = implode(',', $model->getErrors($attribute));
             return false;
         }
     }]);
 }
开发者ID:GT-Volk,项目名称:ManagerOrganizer,代码行数:16,代码来源:UsersController.php

示例6: readStdinUser

 /**
  * @param string $prompt
  * @param \yii\base\Model $model
  * @param string $field
  * @param string $default
  * @return string
  */
 private function readStdinUser($prompt, $model, $field, $default = '')
 {
     while (!isset($input) || !$model->validate(array($field))) {
         echo $prompt . ($default ? " [{$default}]" : '') . ': ';
         $input = trim(fgets(STDIN));
         if (empty($input) && !empty($default)) {
             $input = $default;
         }
         $model->{$field} = $input;
     }
     return $input;
 }
开发者ID:ezsky,项目名称:yii2-platform-core,代码行数:19,代码来源:m100000_000001_app_site_setup.php

示例7: verifyForeignKey

 /**
  * Verifies that given attribute may contains given values
  * @param \yii\base\Model $model
  * @param string $attr
  * @param string $specify
  */
 public function verifyForeignKey(\yii\base\Model $model, $attr, $classname, $specify = '%s is foreign key')
 {
     $this->_verificated = $model;
     $pk = static::valMaxPrimaryKey($classname);
     $this->specify(sprintf($specify, $attr), function () use($attr, $pk) {
         \Codeception\Util\Debug::debug('- verifying FOREIGN KEY');
         $this->_verificated->{$attr} = $pk;
         verify($this->_verificated->validate([$attr]))->true();
         $this->_verificated->{$attr} = $pk + 1;
         verify($this->_verificated->validate([$attr]))->false();
     });
 }
开发者ID:dlds,项目名称:yii2-giixer,代码行数:18,代码来源:GxVerification.php

示例8: validate

 public function validate($attributeNames = NULL, $clearErrors = true)
 {
     foreach ($this->_attributes as $attribute => $value) {
         if ($this->isSerializable($attribute)) {
             $data = json_decode($value, true);
             if (!is_array($data) || json_last_error()) {
                 $this->addError($attribute, "Not valid json");
                 return false;
             }
         }
     }
     return parent::validate($attributeNames = NULL, $clearErrors = true);
 }
开发者ID:bariew,项目名称:yii2-module-cms-module,代码行数:13,代码来源:Param.php

示例9: validate

 public function validate($attributes = null, $clearErrors = true)
 {
     parent::validate($attributes, $clearErrors);
     //每次只返回一个错误
     $error = $this->getErrors();
     $i = 0;
     foreach ($error as $key => $value) {
         if ($i > 0) {
             $this->clearErrors($key);
         }
         $i++;
     }
     return !$this->hasErrors();
 }
开发者ID:VampireMe,项目名称:admin-9939-com,代码行数:14,代码来源:LoginForm.php

示例10: validate

 /**
  * Validates a ProfileFieldType
  *
  * This is only necessary when its linked to a profileField and the profiletype
  * has the current type of profilefieldtype
  *
  * @return boolean
  */
 public function validate($attributes = null, $clearErrors = true)
 {
     // Bound to a profile field?
     if ($this->profileField != null) {
         // Current Profile Field matches the selected profile field
         if ($this->profileField->field_type_class == get_class($this)) {
             return parent::validate($attributes, $clearErrors);
         }
     }
     return true;
 }
开发者ID:kreativmind,项目名称:humhub,代码行数:19,代码来源:BaseType.php

示例11: validate

    public function validate($attributeNames = null, $clearErrors= true){
        $this->image=UploadedFile::getInstance($this,'image');

        if(!parent::validate($attributeNames, $clearErrors)){
            $_message = Auction::loggerMessageFormat('Dealer Registration not validated with following Param',$this->attributes());

            Auction::error($_message);
            return false;
        }

        if($this->image instanceof UploadedFile){

            if(!getimagesize($this->image->tempName)){
                $this->addError('image','Please Upload a valid Image');
                return false;
            }

            $this->trigger(Events::UPLOAD_IMAGE);
        }
        return true;

    }
开发者ID:harish-reglobbe,项目名称:Auction,代码行数:22,代码来源:CompanyRegistration.php

示例12: validateModel

 /**
  * Performs the data validation.
  * @param Model $model
  * @return boolean whether the validation is successful without any error.
  */
 protected function validateModel($model)
 {
     return $model->validate();
 }
开发者ID:manyoubaby123,项目名称:imshop,代码行数:9,代码来源:ModelAction.php

示例13: saveConfigurationModel

 /**
  * Saves configuration model. Performs validation if needed.
  *
  * @param \yii\base\Model $model
  * @param bool $validate
  * @param bool $apply
  * @return bool
  */
 public function saveConfigurationModel($model, $validate = true, $apply = true)
 {
     if (!$model) {
         return false;
     }
     if ($validate && !$model->validate()) {
         return false;
     }
     if ($this->modelClass) {
         //If modelClass is using
         $modelClass = $this->modelClass;
         //Check object and save
         if ($model instanceof $modelClass && $this->_keyStorage->set($this->getKey(), $model)) {
             //Apply new configuration
             if ($apply) {
                 $this->_configuration = $model;
                 $this->configure();
             }
             return true;
         } else {
             return false;
         }
     } else {
         return $this->saveConfigurationArray($model->getAttributes(), $apply);
     }
 }
开发者ID:maddoger,项目名称:yii2-cms-core,代码行数:34,代码来源:ConfigurationBehavior.php

示例14: validateModel

 /**
  * @param \yii\base\Model $model
  * @param array $attributes
  * @return bool
  */
 private function validateModel(\yii\base\Model $model, array $attributes)
 {
     $model->attributes = $attributes;
     if ($model->validate() !== true) {
         $this->errors[] = $model->getFirstErrors();
         return false;
     }
     return true;
 }
开发者ID:anmoroz,项目名称:yii2-analytics,代码行数:14,代码来源:ElasticaQueryBuilder.php

示例15: validate

 /**
  * Validates one or several models and returns an error message array indexed by the attribute IDs.
  * This is a helper method that simplifies the way of writing AJAX validation code.
  *
  * For example, you may use the following code in a controller action to respond
  * to an AJAX validation request:
  *
  * ```php
  * $model = new Post;
  * $model->load($_POST);
  * if (Yii::$app->request->isAjax) {
  *     Yii::$app->response->format = Response::FORMAT_JSON;
  *     return ActiveForm::validate($model);
  * }
  * // ... respond to non-AJAX request ...
  * ```
  *
  * To validate multiple models, simply pass each model as a parameter to this method, like
  * the following:
  *
  * ```php
  * ActiveForm::validate($model1, $model2, ...);
  * ```
  *
  * @param Model $model the model to be validated
  * @param mixed $attributes list of attributes that should be validated.
  * If this parameter is empty, it means any attribute listed in the applicable
  * validation rules should be validated.
  *
  * When this method is used to validate multiple models, this parameter will be interpreted
  * as a model.
  *
  * @return array the error message array indexed by the attribute IDs.
  */
 public static function validate($model, $attributes = null)
 {
     $result = [];
     if ($attributes instanceof Model) {
         // validating multiple models
         $models = func_get_args();
         $attributes = null;
     } else {
         $models = [$model];
     }
     /* @var $model Model */
     foreach ($models as $model) {
         $model->validate($attributes);
         foreach ($model->getErrors() as $attribute => $errors) {
             $result[Html::getInputId($model, $attribute)] = $errors;
         }
     }
     return $result;
 }
开发者ID:sadiqhirani,项目名称:yii2,代码行数:53,代码来源:ActiveForm.php


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