Symfony Routing注释无法识别

时间:2015-03-16 11:45:11

标签: symfony routing

我在routing.yml文件中声明了以下内容:

AcmeFrontendBundle:
  resource: "@AcmeFrontendBundle/Controller"
  type: annotation

然后我在控制器中调用它(这个有效):

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
....
class ArticleVariantController extends Controller
{ 
....
/**
* Set delete status to an image
* @Route("/article-variant/soft-delete-image-ajax/{id}", name="acme_frontend_article_variant_soft_delete_image")
* @Method({"POST"})
*
* @param integer $id Article Erp Id
* @return mixed
*/
public function softDeleteImageAjaxAction($id)
{
    return $this->deleteImageHandler($id);
}

但是这个没有被识别为路由(只有我将它添加到routing.yml文件中 - 我不想这样做):

/*
* Deactivate article variant
* @Route("/article-variant/deactivate-article-variant-ajax/{id}", name="acme_frontend_deactivate_article_variant_ajax")
* @Method({"POST"})
*
* @param integer $id article Id
* @return mixed
*/
public function deactivateArticleVariantAjaxAction($id)
{
   return $this->articleVariantsHandler($id);
}

我错过了什么吗?

1 个答案:

答案 0 :(得分:0)

问题是PHPDoc声明......

就是这样:

/*
* Deactivate article variant
* @Route("/article-variant/deactivate-article-variant-ajax/{id}", name="acme_frontend_deactivate_article_variant_ajax")
* @Method({"POST"})
*
* @param integer $id article Id
* @return mixed
*/

这应该是这个注释开头的第二个明星

/** <- this one here!
* Deactivate article variant
* @Route("/article-variant/deactivate-article-variant-ajax/{id}", name="acme_frontend_deactivate_article_variant_ajax")
* @Method({"POST"})
*
* @param integer $id article Id
* @return mixed
*/

使用PHPStorm快捷键/ * ctrl + enter ...应该是/ ** ctrl +输入不要将其作为注释/* ... */而是作为PHPDoc声明。