Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for using properties/getters for label creation #14

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

barthuttinga
Copy link

Related to issue #3.

I added support for using properties/getters for label creation when using the ParamConverter from the 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.

@barthuttinga
Copy link
Author

Hi @peterhil, what about merging in this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant