yii2-slug-behavior This solution allows you to generate good slug urls.(Semantic URL)

Yii2 slug behavior (Semantic URL)

  1. Installation
  2. How to use
  3. Links
  4. Demo (view urls)

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

Links

Demo (view urls)

skeeks!
SkeekS CMS (Yii2) — quickly, easily and effectively!
skeeks.com | cms.skeeks.com

1 0
4 followers
0 downloads
Yii Version: 2.0.*
License: BSD-3-Clause
Category: Web Service
Developed by: skeeks
Created on: Nov 4, 2017
Last updated: 5 years ago
Github Repository

Related Extensions