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


PHP ActiveRecord::addError方法代码示例

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


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

示例1: saveData

 /**
  * @param array $data
  */
 private function saveData(array $data)
 {
     foreach ($this->getLanguages() as $locale => $language) {
         /** @var ActiveRecord $translation */
         $translation = $this->owner->getTranslation($locale)->one();
         if ($translation === null) {
             $translation = new $this->translationModelName();
             $translation->{$this->translationOwnerField} = $this->owner->{$this->ownerPrimaryKey};
             $translation->{$this->languageField} = $language->id;
         }
         if (isset($data[$locale])) {
             $translation->setAttributes($data[$locale]);
         }
         if (!$translation->save()) {
             $this->owner->addError($locale, $translation->getErrors());
         }
     }
 }
开发者ID:gbksoft,项目名称:yii2-multilingual,代码行数:21,代码来源:Multilingual.php

示例2: addError

 public function addError($error, $message = null)
 {
     if ($message != null) {
         parent::addError($error, $message);
     } else {
         list($attribute, $error) = $error;
         parent::addError($attribute, $error);
     }
 }
开发者ID:JiltImageBoard,项目名称:jilt-backend,代码行数:9,代码来源:ARExtended.php

示例3: beforeValidate

 /**
  * @param $event
  * Try to apply crop before validate, because it may generate errors
  */
 public function beforeValidate($event)
 {
     $file = $this->file = UploadedFile::getInstance($this->_model, "__{$this->attribute}_file__");
     if ($file && !$file->hasError) {
         $asp = $this->propValue('aspectRatio');
         if ($asp > 30) {
             // Uploader widget sets aspect ratio at 1000 x real value
             $asp /= 1000;
             // compensate
             $this->_model->{$this->aspectRatio} = $asp;
         }
         // convert crop data from Json to array
         $crop = Json::decode($this->crop);
         // open image
         $image = $this->_image = Image::getImagine()->open($file->tempName);
         $imgSize = $image->getSize();
         $ww = $imgSize->getWidth();
         $hh = $imgSize->getHeight();
         $error = !$this->allowTooSmall;
         $cropSize = $this->propValue('cropSize');
         // Apply crop, if possible
         if ($crop['w'] > 0 && $crop['h'] > 0) {
             $error = $asp > 1 ? $crop['w'] < $cropSize : $crop['h'] < $cropSize;
             if (!$error) {
                 $image->crop(new Point($crop['x'], $crop['y']), new Box($crop['w'], $crop['h']));
             }
         } else {
             $asp = $ww / $hh;
             if (!is_numeric($this->aspectRatio)) {
                 $this->_model->{$this->aspectRatio} = $asp;
             }
         }
         if ($error) {
             // set error in model
             $this->_model->addError($this->attribute, sprintf($this->tooSmallMsg, $file->name, $ww, $hh));
             $event->isValid = false;
         }
     }
 }
开发者ID:sjaakp,项目名称:yii2-illustrated-behavior,代码行数:43,代码来源:Illustration.php

示例4: afterTransaction

 public function afterTransaction()
 {
     if ($this->hasErrors()) {
         if ($this->ownerAddErrors) {
             foreach ($this->relations as $relation) {
                 if ($this->errors[$relation]) {
                     $this->owner->addErrors($this->errors[$relation]);
                 }
             }
         } else {
             $this->owner->addError('ALL', 'error');
             // что бы работал owner->hasErrors
         }
     }
     if ($this->transaction !== null) {
         if ($this->hasErrors()) {
             $this->transaction->rollBack();
         } else {
             $this->transaction->commit();
         }
     }
 }
开发者ID:dd174,项目名称:yii2-related-behavior,代码行数:22,代码来源:RelatedBehavior.php


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