當前位置: 首頁>>代碼示例>>PHP>>正文


PHP AttributeBehavior::getValue方法代碼示例

本文整理匯總了PHP中yii\behaviors\AttributeBehavior::getValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP AttributeBehavior::getValue方法的具體用法?PHP AttributeBehavior::getValue怎麽用?PHP AttributeBehavior::getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在yii\behaviors\AttributeBehavior的用法示例。


在下文中一共展示了AttributeBehavior::getValue方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getValue

 /**
  * @inheritdoc
  */
 protected function getValue($event)
 {
     if ($this->attribute !== null) {
         if ($this->isNewSlugNeeded()) {
             $slugParts = [];
             foreach ((array) $this->attribute as $attribute) {
                 $slugParts[] = $this->owner->{$attribute};
             }
             $slug = $this->generateSlug($slugParts);
         } else {
             return $this->owner->{$this->slugAttribute};
         }
     } else {
         $slug = parent::getValue($event);
     }
     return $this->ensureUnique ? $this->makeUnique($slug) : $slug;
 }
開發者ID:arogachev,項目名稱:yii2,代碼行數:20,代碼來源:SluggableBehavior.php

示例2: getValue

 /**
  * @inheritdoc
  */
 protected function getValue($event)
 {
     $isNewSlug = true;
     if ($this->attribute !== null) {
         $attributes = (array) $this->attribute;
         /* @var $owner BaseActiveRecord */
         $owner = $this->owner;
         if (!empty($owner->{$this->slugAttribute})) {
             $isNewSlug = false;
             if (!$this->immutable) {
                 foreach ($attributes as $attribute) {
                     if ($owner->isAttributeChanged($attribute)) {
                         $isNewSlug = true;
                         break;
                     }
                 }
             }
         }
         if ($isNewSlug) {
             $slugParts = [];
             foreach ($attributes as $attribute) {
                 $slugParts[] = $owner->{$attribute};
             }
             $slug = $this->generateSlug($slugParts);
         } else {
             $slug = $owner->{$this->slugAttribute};
         }
     } else {
         $slug = parent::getValue($event);
     }
     if ($this->ensureUnique && $isNewSlug) {
         $baseSlug = $slug;
         $iteration = 0;
         while (!$this->validateSlug($slug)) {
             $iteration++;
             $slug = $this->generateUniqueSlug($baseSlug, $iteration);
         }
     }
     return $slug;
 }
開發者ID:SergAHell,項目名稱:yii2,代碼行數:43,代碼來源:SluggableBehavior.php

示例3: getValue

 /**
  * @inheritdoc
  *
  * In case, when the [[value]] is `null`, the result of the PHP function [time()](http://php.net/manual/en/function.time.php)
  * will be used as value.
  */
 protected function getValue($event)
 {
     if ($this->value === null) {
         return time();
     }
     return parent::getValue($event);
 }
開發者ID:assad2012,項目名稱:yii2,代碼行數:13,代碼來源:TimestampBehavior.php

示例4: getValue

 /**
  * @inheritdoc
  *
  * In case, when the [[value]] property is `null`, the value of `Yii::$app->user->id` will be used as the value.
  */
 protected function getValue($event)
 {
     if ($this->value === null) {
         $user = Yii::$app->get('user', false);
         return $user && !$user->isGuest ? $user->id : null;
     }
     return parent::getValue($event);
 }
開發者ID:Abbas-Hashemian,項目名稱:yii2,代碼行數:13,代碼來源:BlameableBehavior.php

示例5: getValue

 /**
  * @inheritdoc
  *
  * In case, when the [[value]] is `null`, position of last created entity or default value
  * will be used as value.
  */
 protected function getValue($event)
 {
     if ($this->value === null) {
         if (!$this->owner instanceof ActiveRecordInterface) {
             throw new \LogicException('Owner should be instanceof ActiveRecordInterface');
         }
         if (!($last = $this->owner->find()->orderBy([$this->positionAttribute => SORT_DESC])->one())) {
             return $this->defaultValue;
         }
         return $last->{$this->positionAttribute} + 1;
     }
     return parent::getValue($event);
 }
開發者ID:yii2-tools,項目名稱:yii2-base,代碼行數:19,代碼來源:PositionBehavior.php

示例6: getValue

 /**
  * @inheritdoc
  *
  * In case, when the [[value]] is `null`, the result of the PHP function [time()](http://php.net/manual/en/function.time.php)
  * will be used as value.
  */
 protected function getValue($event)
 {
     if ($this->value === null) {
         return \Yii::$app->user->id;
     }
     return parent::getValue($event);
 }
開發者ID:tugmaks,項目名稱:yii2-creator-behavior,代碼行數:13,代碼來源:CreatorBehavior.php


注:本文中的yii\behaviors\AttributeBehavior::getValue方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。