为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

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

1 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

不知道如何以及为什么,但在我的树枝文件中呈现了该功能:


<p class="media-body pb-3 mb-0  small lh-125 border-bottom border-gray">

        <strong class="text-gray-dark">Autheur : </strong>

        <a href="{{ path('theme_created_by', {'lastname': theme.user.lastname}) }}">

             {{ theme.user.lastname }}

        </a>

        <br/>

        <a href="{{ path( 'theme_show', {'id' : theme.id} ) }}">

            <strong>{{ theme.name }}</strong><br/>

        </a>

我将该路径行替换为:


<a href="{{ path('theme_created_by', {'username': theme.user.username}) }}">

             {{ theme.user.lastname }}

        </a>

也更改了我的路线中传递的参数:username @Route("/themes/by/{username}", name="theme_created_by") 现在它可以工作了..


查看完整回答
反对 回复 2023-09-22
  • 1 回答
  • 0 关注
  • 168 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信