本文整理汇总了PHP中Slug::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Slug::create方法的具体用法?PHP Slug::create怎么用?PHP Slug::create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slug
的用法示例。
在下文中一共展示了Slug::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setNameField
public function setNameField($data, $value)
{
if ($data->get(self::SLUG) == null) {
$data->set(self::SLUG, Slug::create($value));
}
return $value;
}
示例2: actionUpdate
public function actionUpdate($id)
{
$page = $this->loadModel($id);
if (isset($_POST['Page'])) {
if (Settings::get('SEO', 'slugs_enabled')) {
if (isset($page->slug)) {
if (isset($page->slug->slug) && $_POST['Page']['slug'] != $page->slug->slug) {
if ($_POST['Page']['slug'] == '') {
$page->slug->delete();
$page->slug = NULL;
} else {
$page->slug->change($_POST['Page']['slug']);
}
}
} else {
$page->slug = Slug::create($_POST['Page']['slug'], array('view', 'id' => $id));
$page->save();
}
}
try {
if ($page->save()) {
$this->redirect(array('view', 'id' => $page->id));
}
} catch (Exception $e) {
$page->addError('', $e->getMessage());
}
}
$this->render('update', array('page' => $page));
}
示例3: boot
/**
* When the model boots, register a created event listener that will create a slug,
* using the model's id as the salt value for the generation of thee slug.
*/
public static function boot()
{
parent::boot();
static::created(function ($model) {
$model->slug = Slug::create($model->id);
$model->save();
});
}
示例4: afterSave
public function afterSave($event)
{
//slug for pages are handled in PageController, to prevent infinite loop
if (get_class($this->owner) == 'Page') {
return;
}
$page = $this->owner->page;
if (Settings::get('SEO', 'slugs_enabled') && isset($_POST['Page']['slug']) && $_POST['Page']['slug'] != '') {
if ($this->owner->scenario == 'insert' || $this->owner->scenario == 'update' && !isset($page->slug)) {
//get the page
$page = Page::model()->findByPk($page->id);
//save the slug
$page->slug = Slug::create($_POST['Page']['slug'], array('view', 'id' => $this->owner->id));
$page->save();
}
}
}