PHPackages                             josegonzalez/cakephp-dynamic-route - 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. josegonzalez/cakephp-dynamic-route

ActiveCakephp-plugin

josegonzalez/cakephp-dynamic-route
==================================

Automagicallydatabase-backed dynamic routes for cakephp

12103[1 PRs](https://github.com/josegonzalez/cakephp-dynamic-route/pulls)PHP

Since Nov 29Pushed 9y ago3 watchersCompare

[ Source](https://github.com/josegonzalez/cakephp-dynamic-route)[ Packagist](https://packagist.org/packages/josegonzalez/cakephp-dynamic-route)[ RSS](/packages/josegonzalez-cakephp-dynamic-route/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

[![Build Status](https://camo.githubusercontent.com/507718f942f6126e5b9df5503836592fba92c134c67d915e3319383bec3ec524/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f6a6f7365676f6e7a616c657a2f63616b657068702d64796e616d69632d726f7574652f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/josegonzalez/cakephp-dynamic-route)[![Coverage Status](https://camo.githubusercontent.com/4a384e7a085d4546cbbf53e0e6645315a11ca4be679647ae1458ec0e6c1e4572/68747470733a2f2f696d672e736869656c64732e696f2f636f766572616c6c732f6a6f7365676f6e7a616c657a2f63616b657068702d64796e616d69632d726f7574652e7376673f7374796c653d666c61742d737175617265)](https://coveralls.io/r/josegonzalez/cakephp-dynamic-route?branch=master)[![Total Downloads](https://camo.githubusercontent.com/25da88206cc488af7b61c3a769d071b7355c1b8e09bf3f6c17ea8a2a5140a902/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a6f7365676f6e7a616c657a2f63616b657068702d64796e616d69632d726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-dynamic-route)[![Latest Stable Version](https://camo.githubusercontent.com/c43ea24957bf09e698e414063aad28f0e3dfc21aec73ae4fafc7d0de410db80a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a6f7365676f6e7a616c657a2f63616b657068702d64796e616d69632d726f7574652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/josegonzalez/cakephp-dynamic-route)[![Documentation Status](https://camo.githubusercontent.com/7ef45f00a3f5d64d85b53625d1a570b93e7f7f29bc81fe39202df9e3b7b89c04/68747470733a2f2f72656164746865646f63732e6f72672f70726f6a656374732f63616b657068702d64796e616d69632d726f7574652f62616467652f3f76657273696f6e3d6c6174657374267374796c653d666c61742d737175617265)](https://readthedocs.org/projects/cakephp-dynamic-route/?badge=latest)[![Gratipay](https://camo.githubusercontent.com/40a48c7b3fc02e9d39dd715fe09e404c4cb2e89288c6ace0773d2aab6913b46f/68747470733a2f2f696d672e736869656c64732e696f2f67726174697061792f6a6f7365676f6e7a616c657a2e7376673f7374796c653d666c61742d737175617265)](https://gratipay.com/~josegonzalez/)

DynamicRoute Plugin (For CakePHP 2.0)
=====================================

[](#dynamicroute-plugin-for-cakephp-20)

Read routes from a database into `routes.php` quickly and easily

Background
----------

[](#background)

As with the other route class I built, someone asked in IRC if it would be possible to read the routes from the database and load them into the `app/Config/routes.php` file on the fly. I decided this was true, and this is the result.

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

[](#requirements)

- PHP 5.2+
- CakePHP 2.0

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

[](#installation)

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

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

```
{
    "require": {
        "josegonzalez/cakephp-dynamic-route": "1.0.0"
    }
}

```

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/DynamicRoute` 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/Plugin`
- Rename the folder you just copied to `DynamicRoute`

*\[GIT Submodule\]*

In your app directory type:

```
git submodule add git://github.com/josegonzalez/cakephp-dynamic-route.git Plugin/DynamicRoute
git submodule init
git submodule update

```

*\[GIT Clone\]*

In your plugin directory type

```
git clone git://github.com/josegonzalez/cakephp-dynamic-route.git DynamicRoute

```

### Enable plugin

[](#enable-plugin)

In 2.0 you need to enable the plugin your `app/Config/bootstrap.php` file:

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

```

If you are already using `CakePlugin::loadAll();`, then this is not necessary.

Usage
-----

[](#usage)

Way near the bottom of your `app/Config/routes.php` file, before the line where the default routes are loaded, add the following:

```
App::uses('FancyRoute', 'DynamicRoute.Lib');
FancyRoute::connectFancyRoutes();
```

You can now remove all other **hacks** from your `app/Config/routes.php` file.

What we've enabled is creating `spec|slug` routes in the database. A `spec` would be the internal CakePHP mapping, like `posts/view?id=45` or `events/calendar?date=2011-11-01&category=lol`, while the corresponding `slugs` might be something like `/why-isnt-this-pup-asleep` or `/manchester/cakephp-developers-dance-to-beyonce`.

This `spec|slug` system allows one to have a specialized table for routing - by default the `dynamic_routes` table - which can be used across multiple models and controllers if necessary. It allows a developer to create a simple interface for building internal application routes that a non-developer can use at a later date. This is extremely useful when building content management systems that need a Joomla or Wordpress-like routing system.

Options
-------

[](#options)

`FancyRoute::connectFancyRoutes()` takes an optional array for configuration the route loading:

- `model`: String or Object referencing a CakePHP Model to use for loading records.
    - Default: (string) `DynamicRoute.DynamicRoute`
    - Note: Model being loaded must have a `load` custom find method that returns specs mapping to slugs
- `cacheKey`: Key used for caching the dynamic routes to disk
    - Default: (string) `dynamic_routes`
- `cache`: Whether to cache the db queries
    - Default: (boolean) true

Notes
-----

[](#notes)

Because of the way in which this class works, it is not necessary to call `Router::connect()` on any of the dynamic routes, as this is called internally by the `FancyRoute` class.

The `DynamicRoute` model contains methods for turning a given specification into an internal cakephp request, whether that be a string or array.

You will currently have to create valid `spec|slug` records yourself. Slugs should be prepended with a `/` character, but should not be followed by one. Specs are regular web requests, `$_GET` style.

There is a helper method on the `DynamicRoute` model called `saveNew()`; This method takes a `spec` and `slug`, or an array of data, and returns whether or not the save is successful. It will also do it's best to ensure that the data is properly setup by normalizing specifications and ensuring there slug is in the correct format.

Todo
----

[](#todo)

- Unit Tests
- Backend UI for creating new dynamic routes
- Helper Model method for creating new dynamic routes
- Port to 2.0

License
-------

[](#license)

Copyright (c) 2011 Jose Diaz-Gonzalez

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/f38b500117ee9754ea7a4c56b800c8151ca0605b1715a3b2ff054aae504f7393?d=identicon)[josegonzalez](/maintainers/josegonzalez)

---

Top Contributors

[![josegonzalez](https://avatars.githubusercontent.com/u/65675?v=4)](https://github.com/josegonzalez "josegonzalez (21 commits)")

### Embed Badge

![Health badge](/badges/josegonzalez-cakephp-dynamic-route/health.svg)

```
[![Health](https://phpackages.com/badges/josegonzalez-cakephp-dynamic-route/health.svg)](https://phpackages.com/packages/josegonzalez-cakephp-dynamic-route)
```

PHPackages © 2026

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