All Projects → UseMuffin → Slug

UseMuffin / Slug

Licence: mit
Slugging for CakePHP

Projects that are alternatives of or similar to Slug

Enum
Enumeration list for CakePHP 3
Stars: ✭ 27 (-15.62%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-rest
CakePHP REST Plugin - Easily build REST API endpoints in your CakePHP application.
Stars: ✭ 23 (-28.12%)
Mutual labels:  cakephp, cakephp-plugin
mixerapi
A CakePHP Plugin for RESTful API Development [READ-ONLY]
Stars: ✭ 26 (-18.75%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-mailgun
Mailgun plugin for CakePHP 3
Stars: ✭ 23 (-28.12%)
Mutual labels:  cakephp, cakephp-plugin
Cakepdf
CakePHP plugin for creating and/or rendering PDFs, supporting several popular PDF engines.
Stars: ✭ 360 (+1025%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-api-pagination
📑 CakePHP 4 plugin that injects pagination information into API responses.
Stars: ✭ 39 (+21.88%)
Mutual labels:  cakephp, cakephp-plugin
Users
Users Plugin for CakePHP
Stars: ✭ 488 (+1425%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-translate
A CakePHP plugin to manage translations of your static content the easy way via web backend.
Stars: ✭ 18 (-43.75%)
Mutual labels:  cakephp, cakephp-plugin
Asset compress
An asset compression plugin for CakePHP. Provides file concatenation and a flexible filter system for preprocessing and minification.
Stars: ✭ 370 (+1056.25%)
Mutual labels:  cakephp, cakephp-plugin
crud-users
CakePHP: Users plugin based on the CRUD action classes
Stars: ✭ 17 (-46.87%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-sequence
CakePHP plugin for maintaining a contiguous sequence of records
Stars: ✭ 41 (+28.13%)
Mutual labels:  cakephp, cakephp-plugin
Crud
Production-grade rapid controller development with built in love for API and Search
Stars: ✭ 339 (+959.38%)
Mutual labels:  cakephp, cakephp-plugin
cakephp-glide
CakePHP plugin for using Glide image manipulation library
Stars: ✭ 34 (+6.25%)
Mutual labels:  cakephp, cakephp-plugin
Bootstrap Ui
CakePHP: Transparently use Bootstrap
Stars: ✭ 293 (+815.63%)
Mutual labels:  cakephp, cakephp-plugin
asset-mix
Provides helpers functions for CakePHP to use Laravel Mix.
Stars: ✭ 27 (-15.62%)
Mutual labels:  cakephp, cakephp-plugin
crud-view
CakePHP: Automated admin backend based on your CRUD configuration
Stars: ✭ 45 (+40.63%)
Mutual labels:  cakephp, cakephp-plugin
elastic-search
Elastic search datasource for CakePHP
Stars: ✭ 85 (+165.63%)
Mutual labels:  cakephp, cakephp-plugin
Orderly
Default ordering for your CakePHP tables
Stars: ✭ 21 (-34.37%)
Mutual labels:  cakephp, cakephp-plugin
queue
A queue-interop compatible Queueing library
Stars: ✭ 25 (-21.87%)
Mutual labels:  cakephp, cakephp-plugin
Debug kit
Debug Toolbar for CakePHP applications.
Stars: ✭ 858 (+2581.25%)
Mutual labels:  cakephp, cakephp-plugin

Slug

Build Status Coverage Total Downloads License

Slugging for CakePHP

Installation

Using Composer:

composer require muffin/slug

Load the plugin using the CLI command:

./bin/cake plugin load Muffin/Slug

Usage

To enable slugging add the behavior to your table classes in the initialize() method.

public function initialize(array $config): void
{
    //etc
    $this->addBehavior('Muffin/Slug.Slug', [
        // Optionally define your custom options here (see Configuration)
    ]);
}

Please note that Slug expects a database column named slug to function. If you prefer to use another column make sure to specify the field configuration option.

Searching

If you want to find a record using its slug, a custom finder is provided by the plugin.

// src/Controller/ExamplesController.php
$example = $this->Examples->find('slugged', ['slug' => $slug]);

Configuration

Slug comes with the following configuration options:

  • field: name of the field (column) to hold the slug. Defaults to slug.
  • displayField: name of the field(s) to build the slug from. Defaults to the \Cake\ORM\Table::displayField().
  • separator: defaults to -.
  • replacements: hash of characters (or strings) to custom replace before generating the slug.
  • maxLength: maximum length of a slug. Defaults to the field's limit as defined in the schema (when possible). Otherwise, no limit.
  • slugger: class that implements the Muffin\Slug\SlugInterface. Defaults to Muffin\Slug\Slugger\CakeSlugger.
  • unique:: tells if slugs should be unique. Set this to a callable if you want to customize how unique slugs are generated. Defaults to true.
  • scope: extra conditions used when checking a slug for uniqueness.
  • implementedEvents: events this behavior listens to. Defaults to ['Model.buildValidator' => 'buildValidator', 'Model.beforeSave' => 'beforeSave']. By default the behavior adds validation for the displayField fields to make them required on record creating. If you don't want these auto added validations you can set implementedEvents to just ['Model.beforeSave' => 'beforeSave'].
  • onUpdate: Boolean indicating whether slug should be updated when updating record, defaults to false.
  • onDirty: Boolean indicating whether slug should be updated when slug field is dirty (has a preset value custom value), defaults to false.

Sluggers

The plugin contains two sluggers:

CakeSlugger

The CakeSlugger uses \Cake\Utility\Text::slug() to generate slugs. In the behavior config you can set the slugger key as shown below to pass options to the $options arguments of Text::slug().

'slugger' => [
    'className' => \Muffin\Slug\Slugger\CakeSlugger::class,
    'transliteratorId' => '<A valid ICU Transliterator ID here>'
]

ConcurSlugger

The ConcurSlugger uses concur/slugify to generate slugs. You can use config array similar to the one shown above to pass options to Cocur\Slugify\Slugify's constructor.

Patches & Features

  • Fork
  • Mod, fix
  • Test - this is important, so it's not unintentionally broken
  • Commit - do not mess with license, todo, version, etc. (if you do change any, bump them into commits of their own that I can ignore when I pull)
  • Pull request - bonus point for topic branches

To ensure your PRs are considered for upstream, you MUST follow the CakePHP coding standards.

Bugs & Feedback

http://github.com/usemuffin/slug/issues

License

Copyright (c) 2015-Present, Use Muffin and licensed under The MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].