dongnao6858 2014-09-12 08:10
浏览 39
已采纳

Symfony 2 ParamConverter不工作

I want to use the ParamConverter in symfony2 but i keeps return exceptions.

I have this code :

/**
 * @Route("/")
 * @Route("/{_locale}")
 * @ParamConverter("domain", class="ProdacomMainBundle:PdbDomain")
 * @Template("ProdacomMainBundle:Main:index.html.twig, vars={"domain"})
 */
public function indexAction(PdbDomain $domain) {

}

The error it keeps returning :

    FileLoaderLoadException: Cannot import resource "C:\htdocs\domeinbeheer\src\Prodacom\MainBundle/Controller/" from "C:/htdocs/domeinbeheer/app/configouting.yml". ([Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got 'domain' at position 177 in method Prodacom\MainBundle\Controller\MainController::indexAction().)

And this one :

    AnnotationException: [Syntax Error] Expected Doctrine\Common\Annotations\DocLexer::T_CLOSE_PARENTHESIS, got 'domain' at position 177 in method Prodacom\MainBundle\Controller\MainController::indexAction().

Any ideas ?!

  • 写回答

2条回答 默认 最新

  • douanye8442 2014-09-12 08:40
    关注

    You missed an ending quote here:

     @Template("ProdacomMainBundle:Main:index.html.twig, vars={"domain"})
                                                       ^
    

    That's what both of those exceptions are saying.

    But if you fix those you'll see that $domain cannot be populated unless you have a GET/POST parameter named domain supplying the ID.

    Also if you want the domain parameter to be optional then you'll have to define your index action like this:

    public function indexAction(PdbDomain $domain = null)
    

    Otherwise you'll receive some new exceptions saying that $domain cannot be null.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程