PHPackages                             eberfreitas/cakephp-slugomatic - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. eberfreitas/cakephp-slugomatic

AbandonedArchivedCakephp-plugin

eberfreitas/cakephp-slugomatic
==============================

CakePHP behavior to automatically create slugs for your URLs from database records

0.1.1(10y ago)513.9k6[2 issues](https://github.com/eberfreitas/cakephp-slugomatic/issues)[1 PRs](https://github.com/eberfreitas/cakephp-slugomatic/pulls)MITPHP

Since Dec 14Pushed 10y ago1 watchersCompare

[ Source](https://github.com/eberfreitas/cakephp-slugomatic)[ Packagist](https://packagist.org/packages/eberfreitas/cakephp-slugomatic)[ Docs](http://github.com/eberfreitas/cakephp-slugomatic)[ RSS](/packages/eberfreitas-cakephp-slugomatic/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (2)Dependencies (1)Versions (2)Used By (0)

Slugomatic Plugin
=================

[](#slugomatic-plugin)

[![Build Status](https://camo.githubusercontent.com/c1440e3820fe3ea14914540d1166dfae0aea7672abfc7842136baa324ca2c515/68747470733a2f2f7472617669732d63692e6f72672f65626572667265697461732f63616b657068702d736c75676f6d617469632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/eberfreitas/cakephp-slugomatic) [![Coverage Status](https://camo.githubusercontent.com/52a6555a44f7fdc5e632ebf75736e91d4c738ae43bc26adc324853c7572fff1d/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f65626572667265697461732f63616b657068702d736c75676f6d617469632e737667)](https://coveralls.io/r/eberfreitas/cakephp-slugomatic?branch=master)

Slugomatic is a CakePHP plugin that automatically generate slugs based on your database fields. That way you can easily generate user and SEO friendly URLs for your resources. You can read more about Semantic URLs on [Wikipedia](http://en.wikipedia.org/wiki/Semantic_URL).

**Example**

If you have a record on your database with the title "How to grow a beard", the plugin will generate a slug like "how-to-grow-a-beard". That way you can create links like this:

****

Requirements
------------

[](#requirements)

- CakePHP 2.x (tested on 2.4 and 2.5 but should work on every 2.x release)
- PHP 5.3 or later (should work on 5.2 but it is not tested)

Installation
------------

[](#installation)

**Using [Composer](http://getcomposer.org/)**

Add the plugin to your project's `composer.json` - something like this:

```
{
    "require": {
        "eberfreitas/cakephp-slugomatic": "dev-master"
    }
}
```

Because this plugin has the type `cakephp-plugin` set in it's own `composer.json`, composer knows to install it inside your `/Plugins` directory, rather than in the usual vendors file. It is recommended that you add `/Plugins/Slugomatic` to your .gitignore file. Why? [read this](http://getcomposer.org/doc/faqs/should-i-commit-the-dependencies-in-my-vendor-directory.md).

**Manual**

- Download this:
- Unzip that download
- Copy the resulting folder to app/Plugins
- Rename the folder you just copied to `Slugomatic`

**GIT Submodule**

In your app directory type:

```
git submodule add git://github.com/eberfreitas/cakephp-slugomatic.git plugins/Slugomatic
git submodule init
git submodule update
```

**GIT Clone**

In your plugin directory type:

```
git clone git://github.com/eberfreitas/cakephp-slugomatic.git Slugomatic
```

Usage
-----

[](#usage)

First of all you need to enable the plugin on your application. On your `app/Config/bootstrap.php` add the following line:

```
CakePlugin::load('Slugomatic');
```

You can read more about enabling plugins and the different ways of doing it on [Cake's Book](http://book.cakephp.org/2.0/en/plugins.html#installing-a-plugin).

After that, go to the model where you want to use the plugin and attach the behavior like this:

```
public $actsAs = array(
    'Slugomatic.Slugomatic'
);
```

The plugin will assume that your have a field called `title`. The slug will be created using the data from that field. If you have a different field name, just configure the behavior like this:

```
public $actsAs = array(
    'Slugomatic.Slugomatic' => array(
        'fields' => 'name'
    )
);
```

The plugin will also assume that you have a `slug` field where the generated slug will be stored. Take a look at the options below if you need to change that.

If by any means you have two records with the same title, Slugomatic will identify those records and generate indexed slugs avoiding duplication, like this:

- how-to-grow-a-beard
- how-to-grow-a-beard-1
- how-to-grow-a-beard-2
- how-to-grow-a-beard-x

### Options

[](#options)

When configuring the behavior, you have the following options:

```
public $actsAs = array(
    'Slugomatic.Slugomatic' => array(
        'fields' => 'title',
        'scope' => false,
        'conditions' => false,
        'slugfield' => 'slug',
        'separator' => '-',
        'overwrite' => false,
        'length' => 256,
        'lower' => true
    )
);
```

- `fields`: Specify the source fields for the slug. Defaults to `title`. If you need, you can specify more than one field like this:

    ```
    array('title', 'product_code');
    ```

    That way, if you have a record with the title "Strawberry Cake" and a product\_code like "CK 073", the slug will be something like "strawberry-cake-ck-073".
- `slugfield`: The field on your database that will store the generated slug. Defaults to `slug`.
- `overwrite`: Only applied when updating a record. If `overwrite` is `true`, then when you update the record with a different value, the slug will also be updated/overwrited. Defaults to `false`. **Important!** Ideally, this value should always be `false`. You don't want to break links everywhere with a modified slug from a previously defined resource, so **use this with caution**.
- `length`: Defines the length of the slug. Defaults to 256.
- `lower`: When `true`, transforms the slug text to lowercase. If `false`, the behavior will preserve the text the way it was defined.
- `separator`: The character used to separate words. Defaults to '-'.

#### Additional options for deduplication

[](#additional-options-for-deduplication)

Like stated before, Slugomatic will identify duplicated slugs and generate a properly indexed new slug to avoid that. The plugin also provides two different options that enables you to control the way it identifies duplicated slugs:

- `conditions`: In this option you can define conditions to the query that will identify duplicates just like you define conditions to your regular queries. Example:

    ```
    array(
        'conditions' => array('product_type' => 'box')
    );
    ```

    That way, Slugomatic will only find duplicates if `product_type` is `box`.
- `scope`: This option is very similar to `conditions` but it uses dynamic values. The value will always be the one present on the data being saved. That way you just need to define the field being used for the condition, like this:

    ```
    array(
        'scope' => array('deleted')
    );
    ```

    So, if you are saving a record with the following data:

    ```
    $data = array(
        'title' => 'How to grow a beard',
        'text' => 'Lorem ipsum...',
        'deleted' => 0
    )
    ```

    Slugomatic will only look for duplicates where the field `deleted` is also `0`.

Credits &amp; thanks
====================

[](#credits--thanks)

This plugin is heavily based on [Mariano's SluggableBehavior from the Syrup package](https://github.com/mariano/syrup/blob/master/models/behaviors/sluggable.php). A big thanks to [Friends of Cake](http://friendsofcake.com/) for providing the awesome boilerplate for [travis-ci integration](https://github.com/FriendsOfCake/travis). And finally, thanks to [Jose Diaz-Gonzalez](http://josediazgonzalez.com/) and his [CakeAdvent series](http://josediazgonzalez.com/2013/12/01/testing-your-cakephp-plugins-with-travis/)which helped me to create this plugin properly.

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance12

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

3803d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0557f6ff4744c469038454c1953e93cdb2aeb3e207f747380e6f895df9fa7729?d=identicon)[eberfreitas](/maintainers/eberfreitas)

---

Top Contributors

[![eberfreitas](https://avatars.githubusercontent.com/u/137487?v=4)](https://github.com/eberfreitas "eberfreitas (14 commits)")[![chronon](https://avatars.githubusercontent.com/u/57735?v=4)](https://github.com/chronon "chronon (1 commits)")

---

Tags

pluginslugcakephpBehaviorseo

### Embed Badge

![Health badge](/badges/eberfreitas-cakephp-slugomatic/health.svg)

```
[![Health](https://phpackages.com/badges/eberfreitas-cakephp-slugomatic/health.svg)](https://phpackages.com/packages/eberfreitas-cakephp-slugomatic)
```

###  Alternatives

[sybrew/the-seo-framework

An automated, advanced, accessible, unbranded and extremely fast SEO solution for any WordPress website.

47078.8k](/packages/sybrew-the-seo-framework)[koehlersimon/slug

Helps you managing the URL slugs of your TYPO3 site

2965.7k](/packages/koehlersimon-slug)[itosho/easy-query

CakePHP behavior plugin for easily generating some complicated queries like (bulk) insert/upsert etc.

2623.2k](/packages/itosho-easy-query)[dereuromark/cakephp-meta

A CakePHP plugin for SEO meta tags, OpenGraph and Twitter Cards

1012.9k1](/packages/dereuromark-cakephp-meta)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
