SQLSTATE[22P02]:无效的文本表示:7 错误:整数类型的输入语法无效

早上好,伙计们,我有两个链接的数据库,表是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 作为参数,但它正在接收一个字符串。在阅读文档时,似乎参数已被转换以匹配数据中的任何内容。也许我不完全理解它是如何工作的,只需要一点指导。谢谢


慕沐林林
浏览 288回答 1
1回答

慕斯王

不知道如何以及为什么,但在我的树枝文件中呈现了该功能:<p class="media-body pb-3 mb-0&nbsp; small lh-125 border-bottom border-gray">&nbsp; &nbsp; &nbsp; &nbsp; <strong class="text-gray-dark">Autheur : </strong>&nbsp; &nbsp; &nbsp; &nbsp; <a href="{{ path('theme_created_by', {'lastname': theme.user.lastname}) }}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{ theme.user.lastname }}&nbsp; &nbsp; &nbsp; &nbsp; </a>&nbsp; &nbsp; &nbsp; &nbsp; <br/>&nbsp; &nbsp; &nbsp; &nbsp; <a href="{{ path( 'theme_show', {'id' : theme.id} ) }}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <strong>{{ theme.name }}</strong><br/>&nbsp; &nbsp; &nbsp; &nbsp; </a>我将该路径行替换为:<a href="{{ path('theme_created_by', {'username': theme.user.username}) }}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{ theme.user.lastname }}&nbsp; &nbsp; &nbsp; &nbsp; </a>也更改了我的路线中传递的参数:username @Route("/themes/by/{username}", name="theme_created_by") 现在它可以工作了..
打开App,查看更多内容
随时随地看视频慕课网APP