找不到xxxxBundle \ Entity \ BookPermit对象。 (404 Not Found) - symfony

时间:2017-12-14 07:59:44

标签: php mysql entity-framework symfony

我有一张相关的表格,如下图所示。

bookpermit

id | userfk  | bookfk   |
1  | 6       | 6        |
2  | 6       | 7        |
3  | 7       | 7        |
4  | 8       | 8        |

id | name  | uerfk   |
1  | xyz1   | 6       |
2  | xyz2   | 7       |
3  | xyz3   | 8       |

用户

id | email | phone |
6  | xyz   | xyz   |
7  | xyz   | xyz   |
8  | xyz   | xyz   |

现在我想获取books的结果,它从users表和bookpermit表中找到相应的参数。 books表与具有外键的users表相关。 bookpermit表与books表的外键相关。

以下是图书许可的代码片段

/**
     * @var integer
     *
     * @ORM\Column(name="usersfk", type="integer")
     */
    private $usersfk;

                //getters and setters apply


    /**
     * @var integer
     *
     * @ORM\Column(name="permitid", type="integer")
     */
    private $permitid;

                //getters and setters apply



    // +++++++++++++++++1 relationship mapping between BookPermit and Users ++++++++++++++++++++ //
    //weak enity: book_permit can belong to different users
    /**
     * @ORM\ManyToOne(targetEntity="Users", inversedBy="book_permit")
     * @ORM\JoinColumn(name="usersfk", referencedColumnName="id")
     */
    private $userspermit;


    /**
     * Set Users
     *
     * @param \xxxBundle\Entity\Users $userspermit 
     * @return 
     */
    public function setUsersPermit(\xxxxBundle\Entity\Users $userspermit = null)
    {
        $this->userspermit = $userspermit;

        return $this;
    }

    /**
     * Get Users
     *
     * @return \xxxxBundle\Entity\Users
     */
    public function getUsersPermit()
    {
        return $this->userspermit;
    }





    // +++++++++++++++++1 relationship mapping between BookPermit and Books ++++++++++++++++++++ //
    //weak enity: bookpermit can belong to different books
    /**
     * @ORM\ManyToOne(targetEntity="bookpermit", inversedBy="book_book_permit")
     * @ORM\JoinColumn(name="bookfk", referencedColumnName="usersfk")
     */
    private $bookpermit;


    /**
     * Set Books
     *
     * @param \xxxxBundle\Entity\Books $bookpermit 
     * @return 
     */
        public function setBookPermit(\xxxBundle\Entity\Books $bookpermit = null)
    {
        $this->bookpermit = $bookpermit;

        return $this;
    }

    /**
     * Get Books
     *
     * @return \xxxxBundle\Entity\Books
     */
    public function getBooksPermit()
    {
        return $this->bookpermit;
    }

以下是图书实体

的代码片段
/**
     * @var integer
     *
     * @ORM\Column(name="usersfk", type="integer")
     */
    private $usersfk;

    //getters and setters apply here


// +++++++++++++++++1 relationship mapping between Books and Users ++++++++++++++++++++ //
    //weak enity: many books can belong to a user
    /**
     * @ORM\ManyToOne(targetEntity="Users", inversedBy="books")
     * @ORM\JoinColumn(name="usersfk", referencedColumnName="id")
     */
    private $users;


    /**
     * Set Users
     *
     * @param \xxxxBundle\Entity\Users $users 
     * @return 
     */
    public function setUsers(\xxxxBundle\Entity\Users $users = null)
    {
        $this->users = $users;

        return $this;
    }

    /**
     * Get Users
     *
     * @return \xxxxBundle\Entity\Users
     */
    public function getUsers()
    {
        return $this->users;
    }


    // +++++++++++++++++1 relationship mapping between Books and  BookPermit ++++++++++++++++++++ //
    // 
    //super entity: one user can have different book 
    /**
     * @ORM\OneToMany(targetEntity=BookPermit", mappedBy="bookpermit")
     */
    private $book_book_permit;

    /**
     * Add BookPermit
     *
     * @param \xxxxBundle\Entity\BookPermit $book_book_permit
     * @return BookPermit
     */
    public function addUserBookPermit(\xxxxBundle\Entity\BookPermit $book_book_permit)
    {
        $this->book_book_permit[] = $book_book_permit;

        return $this;
    }

    /**
     * Remove BookPermit
     *
     * @param \xxxxBundle\Entity\BookPermit $book_book_permit
     */
    public function removeUserBookPermit(\xxxxxBundle\Entity\BookPermit $book_book_permit)
    {
        $this->book_book_permit->removeElement($book_book_permit);
    }

    /**
     * Get BookPermit
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getUserBookPermit()
    {
        return $this->book_book_permit;
    }

在我的控制器中,我正在进行此尝试,返回未找到的对象错误

public function displayAction(Request $request, Users $user, BookPermit $bookpermit)
    {

    $bookLists= $em->getRepository("xxxBundle:Books")->findBy(
        array(
            "usersfk" => $user,
            "usersfk" => $bookpermit
        )
    );


    }

在调用上述控制器时,它返回>>>找不到xxxxBundle \ Entity \ BookPermit对象。 (404 Not Found)。

我的方法可能有什么问题

1 个答案:

答案 0 :(得分:1)

从行动中移除提示类型

而不是

public function displayAction(Request $request, Users $user, BookPermit $bookpermit)

更改为

public function displayAction(Request $request, $user, $bookpermit)