xi-project/xi-bundle-breadcrumbs — pull request #14 by barthuttinga (2013-06-12 07:31:36+00:00)
Title: Support for using properties/getters for label creation

Related to issue #3.

I added support for using properties/getters for label creation when using the ParamConverter from the [SensioFrameworkExtraBundle](https://github.com/sensiolabs/SensioFrameworkExtraBundle). In your routing file you can define which property or getter method to use.

Use the ParamConverter in your controller to get the entity:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

/**
* @ParamConverter(name="user", class="MyBundle:User")
*/
public function viewAction($user)
{
//
}

In your routing.yml define which property/getter to use in the breadcrumb labels:

users_view:
pattern: /users/view/{user}
defaults:
_controller: MyBundle:User:view
parent: "users_index"
label: "{user}"
properties:
user: fullName

This will get the user entity from the request (which Sensio's ParamConverter has converted from an id to an entity). It will check if the entity has a public property fullName. If not, it will try to use the public getter method getFullName(). If that also fails, it will try to use the entity's __toString() magic fuction.