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条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度