草庐IT

ParamConverter

全部标签

php - Symfony @ParamConverter : exclude the use if the placeholder does not contain a dot

我有这个Controller:/***{@inheritdoc}**@Route("entity/{domain_host}")*@ParamConverter("entity",class="AppBundle:Entity",options={*"repository_method"="findOneByDomainHost",*"mapping":{"domain_host":"domainHost"},*"map_method_signature"=true*})*/classEntityControllerextendsController{...}通过这种方式,像http:

php - Symfony2 404 错误 : Object Not Found (ParamConverter error)

我创建了一个名为search.html.twig的新边界类,但是当我转到URL(http://localhost:8000/shrubs/search)时,出现以下错误:ERROR-UncaughtPHPExceptionSymfony\Component\HttpKernel\Exception\NotFoundHttpException:"AppBundle\Entity\Shrubsobjectnotfound."atC:\Users\rosmith\shrub_search\vendor\sensio\framework-extra-bundle\Request\ParamCo

php - 如何在 Symfony2 中捕获 ParamConverter 异常?

这是我遇到的异常:Noresultwasfoundforqueryalthoughatleastonerowwasexpected.当在数据库中找不到用户ID时,我基本上会遇到该异常。这是我的路线:localhost/../user/18以及我Controller中的代码:publicfunctionshowAction(User$user){//..}我知道我可以使用内核事件异常来处理这个问题,但是有没有更简单的方法来捕获由ParamConverter生成的异常? 最佳答案 在某些情况下,如果找不到对象,手动抛出异常是很有用的。如

php - 从 $_POST 请求(不是从 URL)使用 ParamConverter

是否可以使用Symfony2中的@ParamConverter注释将通过$_POST请求发送的参数转换为实体?symfony2文档中给出的所有示例都从路由中定义的参数转换实体。设置类似的东西:/***@Route("/")*@ParamConverter("user",class="BvStandardServiceBundle:User",options={"id"="userId"})*/publicfunctionuserAction(User$user){}如果我使用userId$_POST参数中的id调用此路由,它会导致:UnabletoguesshowtogetaDoctr