Download the PHP package cwbit/cakephp-sluggable without Composer
On this page you can find all versions of the php package cwbit/cakephp-sluggable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package cakephp-sluggable
cakephp-sluggable
Plugin for CakePHP 3.x that enables automatic, configurable slugging of database fields
WHY?
Because slugs are great for human-readable yet seo-friendly page titles, urls, image urls, etc! They're pretty much the standard nowadays and CakePHP makes it super easy to give your app the power to create them for you.
HOW?
Just add the Sluggable.Sluggable behaviour to any model whose field(s) you need to slug. See the [usage]() section for customization.
Requirements
- PHP 5.4+
- CakePHP 3.x
TOC
- [Plugin Installation]()
- [Usage]()
- [Examples]()
- [Contributing]()
Plugin Installation
- [Composer Install]()
- [Manual Install]()
- [Loading the plugin in your app]()
- [Setting up the namespace / autoloader]()
Composer Install
This plugin is on Packagist which means it can be easily installed with Composer.
Then simply load the plugin normally in your config/bootstrap.php file
Manual Install
You can also manually load this plugin in your App
loading the plugin in your app
Add the source code in this project into plugins/Sluggable
Then configure your App to actually load this plugin
setting up the namespace / autoloader
Tell the autoloader where to find your namespace in your composer.json file
Then you need to issue the following command on the commandline
If you are unable to get composer autoloading to work, add 'autoload' => true line in your bootstrap.php Plugin::load(..) command (see loading section)
Slug Behavior
The sluggable behavior is extremely easy to implement, simply add it, like any other behavior, to your Table
By default the plugin will automatically generate a slug based on name, will store it in a column called slug and will use a dash - replacement, and will NOT automatically overwrite the slug field whenever name changes.
All of these settings are, of course, configurable.
pattern:name(default)- a
\Cake\Utility\Text::insert()-friendly tokenized string. any of the entity fields are valid options
fieldslug(default)- field in the entity to store the slug
replacement-(default)- string used to replace spaces when building the slug
overwritefalse(default)true, if the slug should ALWAYS be re-generated on save.false, to generate once
Examples
Generate a slug based on the title field instead of name
Generate a slug based on id and title
Generate a slug based on the latest version of the title (always)
Generate a slug normally, but store it in the foo column
Generate a slug using . dots instead of - dashes
Slug Utility
The Sluggable Plugin adds a Utility class Slug that can be called statically. This is the function used by the Behavior to actually generate the slug.
It is capable of handling a string, array, or entity in conjunction with a simple string or Text::insert-friendly pattern.
To use the Utility, simply add the following to your class header
The Utility provides the following function
Examples
To Text::insert via an array...
To Text::insert via Entity properties...
Contributing
If you'd like to contribute, please submit a PR with your changes!
Requests will be accepted more readily if they come complete with TESTS :D