Symfony3对AppBundle\Entity\的查询缺少标识符ID [英] Symfony3 The identifier id is missing for a query of AppBundle\Entity\

查看:113
本文介绍了Symfony3对AppBundle\Entity\的查询缺少标识符ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是symfony的新手,我正尝试使用以下方法将对象从列表传递到新页面:



< a href = {{path('fooUpdate',{'id':item.id})}}>> Update< / a>



Foo对象的列表({%用于列表%}中的项)很好,这些对象已从数据库中完全加载,但是由于以下原因该链接不起作用此教义错误:



AppBundle\Entity\Foo 的查询缺少标识符ID p>

这里是Foo类:

  namespace AppBundle\Entity; 

使用Doctrine\ORM\Mapping作为ORM;

/ **
* @ ORM\实体
* @ ORM\Table(name = foo)
* /
类Foo {

/ **
* @ ORM\Id
* @ ORM\Column(type = integer)
* @ ORM\GeneratedValue
* /
私人$ id;

/ **
* @ ORM\Column(type = string)
* /
private $ description;

//获取和设置

这是控制器方法:

  / ** 
* @Route( / foo / fooUpdate /,name = fooUpdate)
* /
公共功能updateAction($ id,Request $ request){
$ foo = $ this-> getDoctrine()-> getRepository('AppBundle:Foo')-> find ($ id);
return $ this-> render(’/ foo / fooUpdate.html.twig',array(
‘foo’=> $ foo
));
}

链接本身看起来正常,因为错误的URL是:

  http://127.0.0.1:8000/foo/fooUpdate/?id=1 

所以我想念什么?



还有,有什么办法

解决方案

您在路由中缺少该ID:

  @Route( / foo / fooUpdate / {id},name = fooUpdate)


I am new to symfony and I am trying to pass a object from a list to a new page using:

<a href="{{ path('fooUpdate', { 'id': item.id }) }}">Update</a>

The list ({% for item in list %}) of Foo objects is fine, the objects are fully loaded from the database, but the link does not work because of this Doctrine error:

The identifier id is missing for a query of AppBundle\Entity\Foo

Here is the Foo class:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/** 
 * @ORM\Entity
 * @ORM\Table(name="foo") 
 */
class Foo {

/** 
 * @ORM\Id 
 * @ORM\Column(type="integer") 
 * @ORM\GeneratedValue
 */
private $id;

/** 
 * @ORM\Column(type="string")    
 */
private $description;

//getters and setters

And here is the controller method:

/**
 * @Route("/foo/fooUpdate/", name="fooUpdate")
 */
public function updateAction($id, Request $request) {
    $foo = $this->getDoctrine()->getRepository('AppBundle:Foo')->find($id);
    return $this->render('/foo/fooUpdate.html.twig', array(
            'foo' => $foo
    ));
}

The link itself looks like it is working, because the URL of the error is:

http://127.0.0.1:8000/foo/fooUpdate/?id=1

So what am I missing?

Also, is there any way of doing this using POST, so the id will not appear in the URL?

解决方案

You are missing the id in the route:

@Route("/foo/fooUpdate/{id}", name="fooUpdate")

这篇关于Symfony3对AppBundle\Entity\的查询缺少标识符ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆