亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 383 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號