veo/slug-behavior

veo slug behavior

Installs: 18

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 3

Forks: 0

Open Issues: 0

Type:veo-extension

dev-master 2019-06-01 18:42 UTC

This package is auto-updated.

Last update: 2024-03-29 03:51:53 UTC


README

This solution allows you to generate good slug urls. (slug wiki).

Direct generation is engaged in a proven solution cocur/slugify.

Latest Stable Version Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist skeeks/yii2-slug-behavior "*"

or add

"skeeks/yii2-slug-behavior": "*"

How to use

Attach the behavior in your model:

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'
                ]
            ]
        ]
    ];
}

Links

Demo (view urls)

skeeks!
SkeekS CMS (Yii2) — fast, simple, effective!
skeeks.com | cms.skeeks.com