m4nu/object-route-bundle

There is no license information available for the latest version (dev-master) of this package.

Symfony M4nuObjectRouteBundle

Installs: 7

Dependents: 0

Suggesters: 0

Security: 0

Stars: 4

Watchers: 2

Forks: 0

Open Issues: 0

Type:symfony-bundle

dev-master 2013-10-28 07:58 UTC

This package is auto-updated.

Last update: 2024-04-17 21:11:50 UTC


README

This Symfony2 bundle allows to create routes from an object instead of parameters.

Build Status

#How to install ?

##Add theses lines into your deps

[M4nuObjectRouteBundle]
    git=git://github.com/M4nu/M4nuObjectRouteBundle.git
    target=/bundles/M4nu/ObjectRouteBundle

##Add autoloading

#app/autoload.php
$loader->registerNamespaces(array(
    #...
    'M4nu' => __DIR__.'/../vendor/bundles',
));

##Register this bundle

#app/AppKernel.php
$bundles = array(
    #...
    new M4nu\ObjectRouteBundle\M4nuObjectRouteBundle(),
);

##Install the deps

php bin/vendors install

#Examples

Let's say we have a Category and a Message object :

$category = new Category();
$category->setSlug('my-category');

$message = new Message();
$message->setSlug('my-message');
$message->setCategory($category);

And the corresponding route :

message_show:
    pattern:   /message/{category.slug}/{slug}

Create the corresponding route

$router->generate('message_show', $message);
{{ path('message_show', message) }}

Will output: /message/my-category/my-message

Override parameters

$router->generate('message_show', array('_object' => $message, 'slug' => 'my-custom-slug'));
{{ path('message_show', {'_object': message, 'slug': 'my-custom-slug'}) }}

Will output: /message/my-category/my-custom-slug