Symfony2 - How to use @Entity annotations in controllers?

The Symfony manual on ParamConverter provides an 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.

+4
source share
2 answers

Annotation Entityexists only on master (or futur v4). Source file here

But, as you can see, this is just a shortcut to the @ParamConverter annotation with the option expr, so you should use it before the next version.

.

+4

ParameterConverter, .

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 ( ) Bundle.

+1

Source: https://habr.com/ru/post/1669246/


All Articles