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


PHP ActiveRecord::hasAttribute方法代码示例

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


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

示例1: hasAttribute

 public function hasAttribute($name)
 {
     if (!empty($this->{$name})) {
         return true;
     }
     return parent::hasAttribute($name);
 }
开发者ID:noikiy,项目名称:wowewe,代码行数:7,代码来源:MWxAction.php

示例2: afterFind

 /**
  * Handle 'afterFind' event of the owner.
  */
 public function afterFind()
 {
     if ($this->owner->isRelationPopulated('translations') && ($related = $this->owner->getRelatedRecords()['translations'])) {
         $translations = $this->indexByLanguage($related);
         foreach ($this->availableLanguages as $lang) {
             foreach ($this->attributes as $attribute) {
                 foreach ($translations as $translation) {
                     if ($translation->{$this->languageField} == $lang) {
                         $this->setTranslateAttribute($attribute . '_' . $lang, $translation->{$attribute});
                         if ($lang == Yii::$app->language) {
                             $this->setTranslateAttribute($attribute, $translation->{$attribute});
                         }
                     }
                 }
             }
         }
     } else {
         if (!$this->owner->isRelationPopulated('translation')) {
             $this->owner->translation;
         }
         $translation = $this->owner->getRelatedRecords()['translation'];
         if ($translation) {
             foreach ($this->attributes as $attribute) {
                 $this->owner->setTranslateAttribute($attribute, $translation->{$attribute});
             }
         }
     }
     foreach ($this->attributes as $attribute) {
         if ($this->owner->hasAttribute($attribute) && $this->getTranslateAttribute($attribute)) {
             $this->owner->setAttribute($attribute, $this->getTranslateAttribute($attribute));
         }
     }
 }
开发者ID:navatech,项目名称:yii2-multi-language,代码行数:36,代码来源:LanguageBehavior.php

示例3: hasAttribute

 public function hasAttribute($name)
 {
     $class = get_class($this);
     if (!isset(self::$hasAttributeCache[$class][$name])) {
         self::$hasAttributeCache[$class][$name] = parent::hasAttribute($name);
     }
     return self::$hasAttributeCache[$class][$name];
 }
开发者ID:laszlovl,项目名称:yii2-staticactiverecord,代码行数:8,代码来源:ActiveRecord.php

示例4: validateInputParams

 /**
  * Проверка входящих параметров
  *
  * @throws \yii\base\Exception
  */
 private function validateInputParams()
 {
     if (is_null($this->model)) {
         throw new Exception('Параметр model не задан');
     }
     if (!$this->model instanceof ActiveRecord) {
         throw new Exception('Параметр model должен быть объектом класса ActiveRecord');
     }
     if (!is_null($this->author)) {
         if (!$this->author instanceof ActiveRecord) {
             throw new Exception('Параметр author должен быть объектом класса ActiveRecord');
         }
         if (!is_null($this->authorNameAttribute) && !$this->author->hasAttribute($this->authorNameAttribute)) {
             throw new Exception('Параметр author не содержит свойство ' . $this->authorNameAttribute);
         }
         if (!is_null($this->authorAvatarAttribute) && !$this->author->hasAttribute($this->authorAvatarAttribute)) {
             throw new Exception('Параметр author не содержит свойство ' . $this->authorAvatarAttribute);
         }
     }
 }
开发者ID:itsurka,项目名称:yii2-simple-comment,代码行数:25,代码来源:SimpleComment.php

示例5: saveTempFiles

 /**
  * @inheritdoc
  * @return array
  * @throws InvalidConfigException
  */
 public function saveTempFiles()
 {
     if ($this->key === null) {
         throw new InvalidConfigException('You must specify key');
     }
     if ($this->saveDirectoryName === null) {
         throw new InvalidConfigException('You must specify saveDirectoryName');
     }
     if ($this->saveFileModel === null) {
         throw new InvalidConfigException('You must specify save model');
     }
     if (!$this->saveFileModel instanceof ActiveRecord) {
         throw new InvalidConfigException('Save model must be instance of ActiveRecord');
     }
     if ($this->saveFileAttribute === null) {
         throw new InvalidConfigException('You must specify save attribute');
     }
     if ($this->saveFileRelatedAttribute === null) {
         throw new InvalidConfigException('You must specify related attribute');
     }
     if (!$this->saveFileModel->hasAttribute($this->saveFileAttribute)) {
         throw new InvalidConfigException("{$this->saveFileModel->className()} has no attribute name {$this->saveFileAttribute}");
     }
     $files = Yii::$app->session->get($this->key, []);
     foreach ($files as $file) {
         $oldPath = $file['path'];
         $newPath = Yii::$app->params['uploadsPath'] . "/{$this->saveDirectoryName}/" . ($newPath = "{$file['name']}");
         if (file_exists($oldPath)) {
             if (copy($oldPath, $newPath)) {
                 $fileModel = new $this->saveFileModel([$this->saveFileAttribute => $file['name'], $this->saveFileRelatedAttribute => $this->messageModel->id]);
                 $fileModel->save();
             }
         }
     }
     $this->clearTempFolder();
 }
开发者ID:ninetor,项目名称:yii-classifield,代码行数:41,代码来源:Uploader.php

示例6: appendToObjectModel

 /**
  * @param ActiveRecord|HasProperties $model
  * @param string $idAttribute
  * @return bool
  */
 public function appendToObjectModel(ActiveRecord $model, $idAttribute = 'id')
 {
     $object = Object::getForClass($model::className());
     if (null === $object || !$model->hasAttribute($idAttribute)) {
         return false;
     }
     $link = new ObjectPropertyGroup();
     $link->object_id = $object->id;
     $link->object_model_id = $model->{$idAttribute};
     $link->property_group_id = $this->id;
     $result = $link->save();
     $model->updatePropertyGroupsInformation();
     return $result;
 }
开发者ID:cooltheo,项目名称:dotplant2,代码行数:19,代码来源:PropertyGroup.php

示例7: processEmailStatus

 /**
  * Determine status of one email AR. Be called after every email sent.
  * Result statuc can be "succeed", "failed" or "retry".
  * @param CActiveRecord $ar
  * @param bool $isSent
  */
 protected function processEmailStatus(\yii\db\ActiveRecord &$mail, $isSent)
 {
     if (!($mail->hasAttribute($this->retryAttr) && $this->retryTimes > 0)) {
         $mail->{$this->statusAttr} = $isSent ? self::ST_SUCCEED : self::ST_FAILED;
         return;
     }
     if ($isSent) {
         if ($mail->{$this->statusAttr} == self::ST_RETRY) {
             // Current is a retry sending.
             $mail->{$this->retryAttr}++;
         }
         $mail->{$this->statusAttr} = self::ST_SUCCEED;
     } else {
         if ($mail->{$this->statusAttr} == self::ST_NEVER) {
             // First sending and retryable
             $mail->{$this->retryAttr} = 0;
             $mail->{$this->statusAttr} = self::ST_RETRY;
         } elseif (++$mail->{$this->retryAttr} < $this->retryTimes && $mail->{$this->statusAttr} == self::ST_RETRY) {
             // Retry sending and still retryable for next time
         } else {
             // Final failed.
             $mail->{$this->statusAttr} = self::ST_FAILED;
         }
     }
 }
开发者ID:thinker-g,项目名称:yii2-hermes-mailing,代码行数:31,代码来源:DefaultController.php

示例8: hasAttribute

 /**
  * Returns a value indicating whether the model has an attribute with the specified name.
  * @param string $name the name of the attribute
  * @return boolean whether the model has an attribute with the specified name.
  */
 public function hasAttribute($name)
 {
     $result = parent::hasAttribute($name);
     if (!$this->applyDefaults || $this->defaultsApplied) {
         return $result;
     }
     if ($this->getIsNewRecord() && $result) {
         $this->applyDefaults(false);
     }
     return $result;
 }
开发者ID:fangface,项目名称:yii2-concord,代码行数:16,代码来源:ActiveRecord.php

示例9: updateAddr

 /**
  * 根据$addr以及跟新数据更新收货地址
  *
  * $addr = self::find()->where($condition)->one();
  *
  * @param \yii\db\ActiveRecord|\yii\db\ActiveRecord[] $addr 收货地址model对象
  * @param array $data 更新数据
  *              ~
  *              [
  *                  'id' => '主键ID', 'addressee' => '', 'mobile' => '',
  *                  'county' => '', 'address' => '', 'post_code' => '',
  *              ]
  *              ~
  *
  * @return bool
  */
 public function updateAddr($addr, $data)
 {
     foreach ($data as $field => $val) {
         if ($addr->hasAttribute($field)) {
             $addr->{$field} = $val;
         }
     }
     $addr->update_time = time();
     return $addr->save();
 }
开发者ID:songhongyu,项目名称:datecenter,代码行数:26,代码来源:Address.php


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