Download the PHP package zenstruck/object-routing-bundle without Composer
On this page you can find all versions of the php package zenstruck/object-routing-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zenstruck/object-routing-bundle
More information about zenstruck/object-routing-bundle
Files in zenstruck/object-routing-bundle
Package object-routing-bundle
Short Description Symfony2 Bundle that allows generating urls from objects (sf1 style).
License MIT
Homepage http://zenstruck.com/projects/ZenstruckObjectRoutingBundle
Informations about the package object-routing-bundle
ZenstruckObjectRoutingBundle
A Symfony Bundle that enables passing objects to your router. It works by decorating the default router with a custom
ObjectRouter
that transforms objects into a route name and route parameters. These are passed to the default
router.
For those that remember symfony 1, this bundle brings back functionality that was available in that framework.
Installation
-
Install with composer:
composer require zenstruck/object-routing-bundle
- Enable the bundle in the kernel:
Usage
To use this bundle, you must first have an object. Let's use a BlogPost
example:
Next, you must have some routes for that object:
Without this bundle
Now, suppose you want to generate a route for a blog post. The standard way of doing this is as follows:
Twig:
Symfony Controller:
With this bundle
In this bundle's config, setup a mapping of BlogPost
to the blog post routes:
Generating routes for a blog post is now much simpler:
Twig:
Symfony Controller:
Custom Transformations
This bundle comes with a ClassMapObjectTransformer
that uses the bundle's config to map object classes to routes. If
you have a more complex scenario, you can add your own transformers. Simply have your custom transformer implement
Zenstruck\ObjectRoutingBundle\ObjectTransformer\ObjectTransformer
and register it as a service tagged with
zenstruck_object_routing.object_transformer
.
See Zenstruck\ObjectRoutingBundle\ObjectTransformer\ClassMapObjectTransformer
for a reference.
Full Default Config
NOTE 1: This bundle's router uses the PropertyAccess
component to access the object's properties/methods.
NOTE 2: When mapping multiple objects that inherit one another, be sure to order them from child to parent. For
instance, if you had a BlogPost
that has a parent class of Page
and both are mapped, be sure to put BlogPost
before Page
.
All versions of object-routing-bundle with dependencies
symfony/routing Version ~2.3|~3.0
symfony/property-access Version ~2.3|~3.0
symfony/dependency-injection Version ~2.3|~3.0
symfony/config Version ~2.3|~3.0