PrManagerBundle \ Entity \ eb_user的查询缺少标识符ID

时间:2019-05-06 18:29:33

标签: php angular symfony doctrine

我正在尝试使用以下方式从数据库中删除ID所属的对象 前端的<button class="btn btn-danger" (click)="removeUser()"> Delete</button></td>,但该链接无效。我收到一个错误:

The identifier id is missing for a query of PrManagerBundle\Entity\eb_user.

这是我的实体:

namespace PrManagerBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * eb_user
 *
 * @ORM\Table(name="eb_user")
 * @ORM\Entity(repositoryClass="PrManagerBundle\Repository\eb_userRepository")
 */
class eb_user
{
    /**
     * @var int
     *
     * @ORM\Column(name="id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;

/**
 * @var string
 *
 * @ORM\Column(name="nom", type="string", length=255)
 */
private $nom;

/**
 * @var string
 *
 * @ORM\Column(name="prenom", type="string", length=255)
 */
private $prenom;

/**
 * @var int
 *
 * @ORM\Column(name="tel", type="string", nullable = true)
 */
private $tel;

/**
 * @var string
 *
 * @ORM\Column(name="mail", type="string", length=255, nullable = true)
 */
private $mail;

/**
 * @var string
 *
 * @ORM\Column(name="domaine", type="string", length=255, nullable = true)
 */
private $domaine;

/**
 * @ORM\ManyToOne(targetEntity="PrManagerBundle\Entity\eb_role", inversedBy="eb_user")
 */
private $x_eb_role;

/**
 * Get id
 *
 * @return int
 */
public function getId()
{
    return $this->id;
}

/**
 * Set nom
 *
 * @param string $nom
 *
 * @return eb_user
 */
public function setNom($nom)
{
    $this->nom = $nom;

    return $this;
}

/**
 * Get nom
 *
 * @return string
 */
public function getNom()
{
    return $this->nom;
}

/**
 * Set prenom
 *
 * @param string $prenom
 *
 * @return eb_user
 */
public function setPrenom($prenom)
{
    $this->prenom = $prenom;

    return $this;
}

/**
 * Get prenom
 *
 * @return string
 */
public function getPrenom()
{
    return $this->prenom;
}

/**
 * Set tel
 *
 * @param integer $tel
 *
 * @return eb_user
 */
public function setTel($tel)
{
    $this->tel = $tel;

    return $this;
}

/**
 * Get tel
 *
 * @return int
 */
public function getTel()
{
    return $this->tel;
}

/**
 * Set mail
 *
 * @param string $mail
 *
 * @return eb_user
 */
public function setMail($mail)
{
    $this->mail = $mail;

    return $this;
}

/**
 * Get mail
 *
 * @return string
 */
public function getMail()
{
    return $this->mail;
}

/**
 * Set domaine
 *
 * @param string $domaine
 *
 * @return eb_user
 */
public function setDomaine($domaine)
{
    $this->domaine = $domaine;

    return $this;
}

/**
 * Get domaine
 *
 * @return string
 */
public function getDomaine()
{
    return $this->domaine;
}
/**
 * Set xEbRole
 *
 * @param \PrManagerBundle\Entity\eb_role $xEbRole
 *
 * @return eb_user
 */
public function setXEbRole(\PrManagerBundle\Entity\eb_role $xEbRole = null)
{
    $this->x_eb_role = $xEbRole;

    return $this;
}

/**
 * Get xEbRole
 *
 * @return \PrManagerBundle\Entity\eb_role
 */
public function getXEbRole()
{
    return $this->x_eb_role;
}

}

控制器:

public function removeAction(Request $request)
    {
        $em = $this->getDoctrine()->getManager();
        $userInfo = json_decode( $request->request->get("user") );
        $eb_user = $em->getRepository('PrManagerBundle:eb_user')->find($request->request->get('id'));
        $em->remove($eb_user);
        $em->flush(); 
        $em->clear();   
        return $this->returnJsonResponse($eb_user);

        /* $repository = $this->getDoctrine()->getRepository(eb_user::class);
        $editUser = $repository->find($id);
        return $this->returnJsonResponse($editUser);*/
    }

和路由在这里:

pr_manager_remove:     路径:/ user / remove / {id}     默认值:{_controller:PrManagerBundle:User:remove}

实际上找不到ID。我希望链接正常工作

1 个答案:

答案 0 :(得分:0)

您正在将userId作为路由参数传递。这就是为什么请求中缺少它的原因。

id应该作为参数传递给函数PrManagerBundle:User:remove。

/**
 * @Route("/user/remove/{id}", name="pr_manager_remove")
 */
public function remove($id)
{
    ...
    $eb_user = $em->getRepository('PrManagerBundle:eb_user')->find($id);
    ...
}