早上好,伙计们,我有两个链接的数据库,表是User和Theme,请记住我对 php 和 symfony 框架不太熟悉。主题链接到用户:
/src/Entity/Theme.php
/**
* @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="published")
* @ORM\JoinColumn(nullable=false)
*/
private $user;
我正在尝试设置一个函数,该函数将显示该用户根据他的姓氏编写的所有主题,根据我的理解, @ORM\ManyToOne(targetEntity="App\Entity\User", inversedBy="published")确保我的主题不仅由用户实体链接,user_id而且还由用户实体链接。
在我的函数中ThemeController.php,我的函数是这样设置的:
/**
* @Route("/theme/show/{lastname}", name="theme_created_by")
* 0@param User $ThemeByUser
*/
public function userThemes(User $ThemeByUser){
$html = $this->twig->render('theme/index.html.twig', [
'themes' => $this->themeRepository->findBy(
['User' => $ThemeByUser], ['created_at' => 'DESC']),
]);
return new Response($html);
}
看来 Doctrine 发出的查询没有通过,我收到此错误:
An exception occurred while executing 'SELECT t0.id AS id_1, t0.name AS name_2, t0.created_at AS created_at_3, t0.updated_at AS updated_at_4, t0.user_id AS user_id_5 FROM theme t0 WHERE t0.id = ?' with params ["Roland"]:
SQLSTATE[22P02]: Invalid text representation: 7 ERROR: invalid input syntax for type integer: "Roland"
这意味着 Doctrine 需要一个 int 作为参数,但它正在接收一个字符串。在阅读文档时,似乎参数已被转换以匹配数据中的任何内容。也许我不完全理解它是如何工作的,只需要一点指导。谢谢
慕斯王