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


PHP site::slugify方法代码示例

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


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

示例1: checkslug

 protected function checkslug()
 {
     if (!$this->loaded()) {
         $slug = $this->slug;
         if (empty($slug)) {
             $slug = $this->title;
         }
         $slug = site::slugify($slug);
         $orgslug = $slug;
         $exists = $this->where('slug', '=', $slug)->count_all();
         $i = 2;
         while ((bool) $exists) {
             $secondtolast = substr($orgslug, strlen($orgslug) - 2, 1);
             $last = substr($orgslug, strlen($orgslug) - 1, 1);
             if ($secondtolast == '-' && is_numeric($last)) {
                 $slug = substr($orgslug, 0, strlen($orgslug) - 1) . ($last + 1);
             } else {
                 $slug = $orgslug . '-' . $i;
             }
             $exists = $this->where('slug', '=', $slug)->count_all();
             $i++;
         }
         $this->slug = $slug;
     } else {
         if ($this->changed('slug')) {
             $slug = $this->slug;
             $slug = site::slugify($slug);
             $orgslug = $slug;
             $exists = $this->where('slug', '=', $slug)->where('id', '!=', $this->id)->count_all();
             $i = 2;
             while ((bool) $exists) {
                 $secondtolast = substr($orgslug, strlen($orgslug) - 2, 1);
                 $last = substr($orgslug, strlen($orgslug) - 1, 1);
                 if ($secondtolast == '-' && is_numeric($last)) {
                     $slug = substr($orgslug, 0, strlen($orgslug) - 1) . ($last + 1);
                 } else {
                     $slug = $orgslug . '-' . $i;
                 }
                 $exists = $this->where('slug', '=', $slug)->where('id', '!=', $this->id)->count_all();
                 $i++;
             }
             $this->slug = $slug;
         }
     }
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:45,代码来源:Stuffwithslugs.php

示例2: action_addtag

 public function action_addtag()
 {
     $file = ORM::factory('File', arr::get($_POST, 'id', false));
     if (!$file->loaded()) {
         ajax::error(__('The file wasn\'t found. Has it been deleted in the meantime?'));
     }
     $tagtext = arr::get($_POST, 'tag', false);
     if (!$tagtext) {
         ajax::error(__('No tag recieved'));
     }
     $slug = site::slugify($tagtext);
     $tag = ORM::factory('Tag')->where('slug', '=', $slug)->find();
     if (!$tag->loaded()) {
         $tag->tag = $tagtext;
         $tag->slug = $slug;
         $tag->save();
     }
     $file->add('tags', $tag);
     ajax::success('ok', array('tag' => array('id' => $tag->id, 'tag' => $tag->tag, 'slug' => $tag->slug)));
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:20,代码来源:Files.php

示例3: check_slug_and_guid

         }
     }
     return $new;
 }
 public function check_slug_and_guid()
 {
     if (empty($this->slug)) {
         if (empty($this->title)) {
             $this->slug = $this->id;
         } else {
             $this->slug = $this->title;
         }
     } elseif ($this->changed('slug')) {
     } else {
         return;
     }
     $this->slug = site::slugify($this->slug);
     $newguid = $this->slug;
     $beforeslug = $this->contenttype->slug;
     if ($this->parent != 0) {
         $parent = ORM::factory('Content')->where('id', '=', $this->parent)->find();
         if ($parent->loaded()) {
             $beforeslug = $parent->guid . '/';
             $newguid = $parent->guid . '/' . $this->slug;
         } else {
             // Parent isn't loaded for some reason. Remove parent id
             $this->parent = 0;
         }
     } else {
         if ($this->contenttype->slug != '') {
             $newguid = $this->contenttype->slug . '/' . $this->slug;
         }
     }
     $existing = ORM::factory('Content')->where('guid', '=', $newguid)->where('id', '!=', $this->id)->find();
     $i = 2;
     $orgslug = $this->slug;
     while ($existing->loaded()) {
         $this->slug = $this->slug . '-' . $i;
         $newguid = $beforeslug . $this->slug;
         $existing = ORM::factory('Content')->where('guid', '=', $newguid)->where('id', '!=', $this->id)->find();
开发者ID:artbypravesh,项目名称:morningpages,代码行数:40,代码来源:Content.php

示例4: create

 public function create(Validation $val = NULL)
 {
     $result = parent::create($val);
     $slug = site::slugify($this->username);
     $orgslug = $slug;
     $existing = ORM::factory('User')->where('slug', '=', $slug)->find();
     $i = 2;
     while ($existing->loaded()) {
         $slug = $orgslug . '-' . $i;
         $i++;
     }
     $this->slug = $slug;
     $this->update();
     $options = ORM::factory('User_Option');
     $options->user_id = $this->id;
     $options->save();
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:17,代码来源:User.php


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