baibaratsky/yii2-slug-behavior

Yii2 slug 行为

安装: 300

依赖: 0

建议者: 0

安全: 0

星标: 3

关注者: 2

分支: 1

开放问题: 0

类型:yii2-extension

dev-master 2015-04-17 09:56 UTC

This package is auto-updated.

Last update: 2024-09-16 14:39:32 UTC


README

在 Yii2 成为公测版本之前,我就已经创建了这种行为。目前,由于 Yii2 已经有了自己的实现 — SluggableBehavior,因此不需要使用此行为。

此 Yii2 模型行为自动化了 slug 生成过程。要将行为附加到模型中,请将以下代码放入您的模型中

    public function behaviors()
   	{
   		return [
   			'slug' => [
   				'class' => Slug::className(),

   				// These parameters are optional, default values presented here:
   				'sourceAttributeName' => 'name', // If you want to make a slug from another attribute, set it here
   				'slugAttributeName' => 'slug', // Name of the attribute containing a slug
                'replacement' => '-', // The replacement to use for spaces in the slug
                'lowercase' => true, // Whether to return the string in lowercase or not
                'unique' => true, // Check if the slug value is unique, add number if not
   			],
   		];
   	}