skeeks / yii2-slug-behavior
Yii2 slug 行为
1.0.0
2017-11-04 09:02 UTC
Requires
- cocur/slugify: ^3.0
- yiisoft/yii2: ^2
This package is auto-updated.
Last update: 2024-08-24 06:15:56 UTC
README
此解决方案允许您生成良好的slug URL。 (slug 维基)。
直接生成采用经过验证的解决方案 cocur/slugify。
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist skeeks/yii2-slug-behavior "*"
或添加
"skeeks/yii2-slug-behavior": "*"
如何使用
在您的模型中附加行为
public function behaviors() { return [ 'slug' => [ 'class' => 'skeeks\yii2\slug\SlugBehavior', 'slugAttribute' => 'slug', //The attribute to be generated 'attribute' => 'name', //The attribute from which will be generated // optional params 'maxLength' => 64, //Maximum length of attribute slug 'minLength' => 3, //Min length of attribute slug 'ensureUnique' => true, 'slugifyOptions' => [ 'lowercase' => true, 'separator' => '-', 'trim' => true //'regexp' => '/([^A-Za-z0-9]|-)+/', //'rulesets' => ['russian'], //@see all options https://github.com/cocur/slugify ] ] ]; }
Yandex translit http://translit-online.ru/yandex.html
public function behaviors() { return [ 'slug' => [ 'class' => 'skeeks\yii2\slug\SlugBehavior', 'slugAttribute' => 'slug', //The attribute to be generated 'attribute' => 'name', //The attribute from which will be generated // optional params 'slugifyOptions' => [ 'rulesets' => [ skeeks\yii2\slug\SlugRuleProvider::YANDEX, 'default' ] ] ] ]; }
链接
演示(查看URLs)
SkeekS CMS (Yii2) — 快速、简单、有效!
skeeks.com | cms.skeeks.com