xety / cake3-sluggable
A simple Cake3 plugin to slug fields and find records by slug.
Installs: 10 054
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 3
Forks: 3
Open Issues: 3
Type:cakephp-plugin
Requires
- php: >=5.4.16
- cakephp/orm: 3.*
Requires (Dev)
- cakephp/cakephp: ~3.0
- cakephp/cakephp-codesniffer: master-dev
- phpunit/phpunit: 4.*
This package is auto-updated.
Last update: 2024-11-04 23:56:20 UTC
README
A simple Cake3 plugin to slug fields and find records by slug.
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' => '_' ] );