PHPackages                             piotrpasich/cakephp-symfony-router - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. piotrpasich/cakephp-symfony-router

ActiveCakephp-plugin[HTTP &amp; Networking](/categories/http)

piotrpasich/cakephp-symfony-router
==================================

A symfony router for cackePhp

0.0.1.x-dev(11y ago)618[1 issues](https://github.com/piotrpasich/cakephp-symfony-router/issues)MITPHP

Since Aug 11Pushed 11y ago1 watchersCompare

[ Source](https://github.com/piotrpasich/cakephp-symfony-router)[ Packagist](https://packagist.org/packages/piotrpasich/cakephp-symfony-router)[ Docs](http://github.com/piotrpasich/cakephp-symfony-router)[ RSS](/packages/piotrpasich-cakephp-symfony-router/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (3)Versions (2)Used By (0)

CakephpSymfonyRouter Plugin
===========================

[](#cakephpsymfonyrouter-plugin)

CakephpSymfonyRouter is a plugin that extends how your default Router can be used. It enables three new features:

- Add named routes
- Manipulate the params from a matched route
- Matches a route only if it conforms to a given condition

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)
- composer

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

[](#installation)

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

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

```
{
    "require": {
        "piotrpasich/cakephp-symfony-router": "dev-master"
    }
}
```

Then you need to install vendors:

```
cd app/Plugins/CakephpSymfonyRouter
composer install
```

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/PowerRouter` 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 `CakephpSymfonyRouter`

**GIT Submodule**

In your app directory type:

```
git submodule add git://github.com/piotrpasich/cakephp-symfony-router.git plugins/CakephpSymfonyRouter
git submodule init
git submodule update
```

**GIT Clone**

In your plugin directory type:

```
git clone git://github.com/piotrpasich/cakephp-symfony-router.git CakephpSymfonyRouter
```

Usage
-----

[](#usage)

CakephpSymfonyRouter is a custom route class that extends on the CakeRoute. This way you can use it to define your routes and take advantage of it's features. Using it will make you able to use routing in CakePHP much easier than it is now.

In order to use the features from CakephpSymfonyRouter, first you need to load the plugin adding the following line in your `app/Config/bootstrap.php`:

```
//app/Config/bootstrap.php
App::build(array('Plugin' => array(ROOT . '/Plugin/')));
CakePlugin::load('CakephpSymfonyRouter');
```

Later, import the library into your "app/Config/routes.php" file like this:

```
//app/Config/routes.php
App::uses('SymfonyRouter', 'CakephpSymfonyRouter.Lib');
App::uses('RouterYmlConfiguration', 'CakephpSymfonyRouter.Lib');

$routerYmlConfiguration = new RouterYmlConfiguration(APP . 'Config' . DS . 'router.yml');
$symfonyRouter = new SymfonyRouter($routerYmlConfiguration);
```

After that you can create own file in app/Config/router.yml like this:

```
home:
    path:      /
    defaults:  { controller: Home,  action: index }
blog:
    path:      /blog
    defaults:  { controller: Blog,  action: index }
blog_post:
    path:      /blog/{slug}
    defaults:  { controller: Blog,  action: post }
```

Matching routes in templates views
----------------------------------

[](#matching-routes-in-templates-views)

To use this Plugin in your Views files and generate Urls you need to add a Helper in your Controller like

```
//app/Controller/BlogController
class BlogController extends AppController
{

    public $helpers = array('CakephpSymfonyRouter.SymfonyRouter');

    /** ... **/
}
```

And then you can generate your url in View:

```
//app/View/Blog/index
