本文整理汇总了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;
}
}
}
示例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)));
}
示例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();
示例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();
}