本文整理匯總了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();
}
}
}