PHP code example of atelfoto / sluggable

1. Go to this page and download the library: Download atelfoto/sluggable library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atelfoto / sluggable example snippets


 //src/Model/Table/model.php
 $this->addBehavior('Sluggable.Sluggable');

    $this->addBehavior('Sluggable.Sluggable', [
        'field' => 'your-field'
        ]
    );
    

    $this->addBehavior('Sluggable.Sluggable', [
        'field' => 'your-field',
        'slug' => 'your-slug'
        ]
    );
    

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

  public function view($value = null)
    {
        $query = $this->Models->findBySlug($value)->firstOrFail();
        $this->set(compact('query'));
    }
  

  //config/routes

  $routes->connect(
        '/the title/:slug',
        ['controller' => 'YourController', "action" => "view"],
        [
            "_name" => "the title",
            "pass" => ['slug'],
        ]
    );