Skip to content
Yii2 slug behavior
Branch: master
Clone or download
Latest commit e40f370 Feb 15, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Service
LICENSE
Slug.php
composer.json
readme.md

readme.md

Yii2 slug behavior

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.5.1"

or add "zelenin/yii2-slug-behavior": "~1.5.1" 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

You can’t perform that action at this time.