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


PHP SluggableBehavior::getValue方法代码示例

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


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

示例1: getValue

 /**
  * @inheritdoc
  */
 protected function getValue($event)
 {
     /* @var $owner ActiveRecord */
     $owner = $this->owner;
     if (!empty($owner->{$this->slugAttribute}) && !$this->slugIsEmpty && $this->immutable) {
         $slug = $owner->{$this->slugAttribute};
     } else {
         if ($owner->getIsNewRecord()) {
             $this->slugIsEmpty = true;
         }
         if ($this->attribute !== null) {
             $attributes = $this->attribute;
             $slugParts = array_map(function ($attribute) {
                 return ArrayHelper::getValue($this->owner, $attribute);
             }, $attributes);
             $slug = $this->slugify(implode($this->replacement, $slugParts), $this->replacement, $this->lowercase);
             if (!$owner->getIsNewRecord() && $this->slugIsEmpty) {
                 $owner->{$this->slugAttribute} = $slug;
                 $owner->save(false, [$this->slugAttribute]);
             }
         } else {
             $slug = parent::getValue($event);
         }
     }
     if ($this->ensureUnique) {
         $baseSlug = $slug;
         $iteration = 0;
         while (!$this->validateSlug($slug)) {
             $iteration++;
             $slug = $this->generateUniqueSlug($baseSlug, $iteration);
         }
     }
     return $slug;
 }
开发者ID:zelenin,项目名称:yii2-slug-behavior,代码行数:37,代码来源:Slug.php

示例2: getValue

 public function getValue($event)
 {
     $this->setLanguage();
     if ($this->language != 'fa') {
         return parent::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 = Inflector::persianSlug(implode('-', $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:ahb360,项目名称:kalpok,代码行数:44,代码来源:SluggableBehavior.php

示例3: getValue

 /**
  * @inheritdoc
  */
 protected function getValue($event)
 {
     $isNewSlug = true;
     if ($this->attribute !== null) {
         $attributes = (array) $this->attribute;
         /* @var $owner BaseActiveRecord */
         $owner = $this->owner;
         if (!$owner->getIsNewRecord() && !empty($owner->{$this->slugAttribute})) {
             $isNewSlug = false;
             foreach ($attributes as $attribute) {
                 if ($owner->isAttributeChanged($attribute) && $this->forceUpdate) {
                     $isNewSlug = true;
                     break;
                 }
             }
         }
         if ($isNewSlug) {
             $slugParts = [];
             foreach ($attributes as $attribute) {
                 $slugParts[] = $owner->{$attribute};
             }
             $oldTransliterator = Inflector::$transliterator;
             if (isset($this->transliterator)) {
                 Inflector::$transliterator = $this->transliterator;
             }
             $slug = Inflector::slug(implode('_', $slugParts));
             Inflector::$transliterator = $oldTransliterator;
         } 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:akula22,项目名称:fifa,代码行数:46,代码来源:SluggableBehavior.php


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