atelfoto / sluggable
Sluggable plugin for CakePHP
Installs: 17
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:cakephp-plugin
Requires
- php: >=8.1
- cakephp/cakephp: ^5.0.0
Requires (Dev)
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2025-04-06 00:29:44 UTC
README
1. Requirements
- cakephp 5.x.x
2. Installation
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require atelfoto/sluggable
- or add it in the composer.json
"require": { "atelfoto/sluggable": "1.*" },
- And in a Table in
initialize();
add this line:
//src/Model/Table/model.php $this->addBehavior('Sluggable.Sluggable');
3. Configuration
3.1. Model Table
- Field
- Default: name
- The field to slug
$this->addBehavior('Sluggable.Sluggable', [ 'field' => 'your-field' ] );
- Slug
- Default: slug
- The slug field name in your database:
$this->addBehavior('Sluggable.Sluggable', [ 'field' => 'your-field', 'slug' => 'your-slug' ] );
- Replacement
-
Default:
-
-
The replacement characters used to replace space:
$this->addBehavior('Sluggable.Sluggable', [ 'replacement' => '_' ]);
-
3.2. Controller
-
To use in a finder:
public function view($value = null) { $query = $this->Models->findBySlug($value)->firstOrFail(); $this->set(compact('query')); }
3.3. Route
-
In the Route
//config/routes $routes->connect( '/the title/:slug', ['controller' => 'YourController', "action" => "view"], [ "_name" => "the title", "pass" => ['slug'], ] );