我有一个相关的表,如下图所示。
图书许可证
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 |
现在我想从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;
}
下面是books实体的代码片段
/**
* @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;
}
在我的控制器中,我正在尝试返回一个object not found错误
public function displayAction(Request $request, Users $user, BookPermit $bookpermit)
{
$bookLists= $em->getRepository("xxxBundle:Books")->findBy(
array(
"usersfk" => $user,
"usersfk" => $bookpermit
)
);
}
在调用上述控制器时,它返回>>>xxxxBundle\Entity\BookPermit object not found。(找不到404)。
我的方法有什么问题
最佳答案
从操作中删除类型提示
而不是这个
public function displayAction(Request $request, Users $user, BookPermit $bookpermit)
更改为
public function displayAction(Request $request, $user, $bookpermit)