/Cake3-Sluggable

A simple Cake3 plugin to slug fields and find records by slug.

Primary LanguagePHPMIT LicenseMIT

Cake3 Sluggable

A simple Cake3 plugin to slug fields and find records by slug.

Build Status Coverage Status Scrutinizer Latest Stable Version Total Downloads License

Requirements

  • CakePHP 3.X

Installation

Run : composer require xety/cake3-sluggable:1.* Or add it in your composer.json:

"require": {
	"xety/cake3-sluggable": "1.*"
},

Usage

In your config/bootstrap.php add :

Plugin::load('Xety/Cake3Sluggable');

In your model initialize():

$this->addBehavior('Xety/Cake3Sluggable.Sluggable');

To use the custom finder :

$this->Users
	->find('slug', [
		'slug' => 'your-slug-here',
		'slugField' => 'Users.slug'
	]);

Configuration

  • field

    Default : title

    The field to slug :

     $this->addBehavior('Xety/Cake3Sluggable.Sluggable', [
     		'field' => 'username'
     	]
     );
  • slug

    Default : slug

    The slug field name in your database :

     $this->addBehavior('Xety/Cake3Sluggable.Sluggable', [
     		'field' => 'username',
     		'slug' => 'slug_username'
     	]
     );
  • replacement

    Default : -

    The replacement characters used to replace space etc :

     $this->addBehavior('Xety/Cake3Sluggable.Sluggable', [
     		'replacement' => '_'
     	]
     );

Contribute

Follow this guide to contribute