3

We're running a project built on top of Zend Framework 1.x, and are considering moving to Symfony 2. We have a domain model mapped with Doctrine 2.

Our (custom built) base controller class extends Zend_Controller_Action to provide a very convenient feature, inspired from Flow3:

Let's say I have this controller:

class UserController extends BaseController
{
    public function editAction(User $user)
    {
        // ...
    }
}

If I load this URL:

/user/edit?user=123

The base controller will automatically load the User entity with identity 123, and pass it as a parameter to the editAction() method. If the user parameter is omitted, or if no User with this identity exists, an exception is thrown.

Is there such an implementation for Symfony 2, or is it possible to implement it, and how?

BenMorel
  • 34,448
  • 50
  • 182
  • 322

1 Answers1

3

The @ParamConverter annotation from SensioFrameworkExtraBundle does exactly that. If you're using the Symfony Standard distribution, you get it out of the box.

Elnur Abdurrakhimov
  • 44,533
  • 10
  • 148
  • 133
  • Looks good, thanks! However it's not exactly the same, as $post is filled with the Post matching the 'id' parameter, and this has to be configured in the router. Whereas what I'm trying to have is an automated mapping of all GET parameters, with the name matching the method signature. The routing is done elsewhere. Any idea? – BenMorel Apr 16 '12 at 17:51