zelenin/yii2-slug-behavior

Yii2 slug behavior

Installs: 3 323

Dependents: 5

Stars: 17

Watchers: 3

Forks: 6

Open Issues: 2

Language: PHP

1.0.0 2015-07-28 22:12 UTC

README

Yii2 slug behavior

Installation

Composer

The preferred way to install this extension is through Composer.

Either run php composer.phar require zelenin/yii2-slug-behavior "~1.0@stable"

or add "zelenin/yii2-slug-behavior": "~1.0@stable" to the require section of your composer.json

Using

Attach the behavior in your model:

public function behaviors()
{
    return [
        'slug' => [
            'class' => 'Zelenin\yii\behaviors\Slug',
            'slugAttribute' => 'slug',
            'attribute' => 'name',
            // optional params
            'ensureUnique' => true,
            'replacement' => '-',
            'lowercase' => true,
            'immutable' => false,
            // If intl extension is enabled, see http://userguide.icu-project.org/transforms/general. 
            'transliterateOptions' => 'Russian-Latin/BGN; Any-Latin; Latin-ASCII; NFD; [:Nonspacing Mark:] Remove; NFC;'
        ]
    ];
}

Slug may be generated from multiple and related attributes:

public function behaviors()
{
    return [
        'slug' => [
            ...
            'attribute' => ['name', 'language.username'],
            ...
        ]
    ];
}

Author

Aleksandr Zelenin, e-mail: aleksandr@zelenin.me