4

Symfony's manual on ParamConverter has this example:

/**
 * @Route("/blog/{post_id}")
 * @Entity("post", expr="repository.find(post_id)")
 */
public function showAction(Post $post)
{
}

Source: http://symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/annotations/converters.html#fetch-via-an-expression

But using @Entity annotation gives me this error.

The annotation "@Entity" in method AppBundle\Controller\CurrencyController::currencyAction() was never imported. Did you maybe forget to add a "use" statement for this annotation?

Obviously, I need to use a namespace, but which one? Please help.

2
  • 1
    You need to do what error message says - import Entity. You forgot to add a "use" statement on the top of the script. Commented Feb 9, 2017 at 9:24
  • 1
    Right, but which one exactly? This was the question. SensioFrameworkExtraBundle does not have @Entity annotation (Not in Symfony2 at least), but the manual suggests to use it. Commented Feb 9, 2017 at 9:49

3 Answers 3

4

The Entity annotation only exist on master (or futur v4). Source file here

But as you can see, this is only a shortcut to @ParamConverter annotation with expr option, so you have to use this one until next release.

Best regards.

Sign up to request clarification or add additional context in comments.

Comments

1

You are trying to use ParameterConverter so this syntax is just wrong.

Use this instead

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;

/**
 * @Route("/blog/{post_id}")
 * @ParamConverter("post_id", class="VendorBundle:Post")
 */
public function showAction(Post $post)
{
}

VendorBundle:Post should be replaced with whatever your Vendor is (if any) and Bundle is.

Comments

1

Using annotation @ParamConverter with option repository_method is deprecated

The repository_method option of @ParamConverter is deprecated and will be removed in 6.0. Use the expr option or @Entity.

Thus it's better to use @Entity (documentation)

You have to add the namespace :

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Entity;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.