atelfoto/sluggable

Sluggable plugin for CakePHP

Installs: 16

Dependents: 0

Suggesters: 0

Security: 0

Stars: 1

Watchers: 1

Forks: 0

Open Issues: 0

Type:cakephp-plugin

5.0.0 2023-10-04 19:03 UTC

This package is auto-updated.

Last update: 2024-05-05 22:26:24 UTC


README

Build Status License Latest Stable Version Packagist PHP Version Support (specify version) GitHub repo size Code Qualité PHP Composer codecov

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'],
          ]
      );