gpt4 book ai didi

php - 如何在 DQL CodeIgniter 中传递变量

转载 作者:行者123 更新时间:2023-11-29 07:14:57 24 4
gpt4 key购买 nike

我在 DQL 中遇到了如何传递 session 用户 ID 的问题

$vars['mood'] = Doctrine_Query::create()
->select(’m.mood_name, a.id, m.account_id’)
->from(’mood m, m.account a’)
->where(’m.account_id=”7″‘)

我想根据当前登录的用户显示数据。

m.account_id=Current_User::user()->id;

这是行不通的

最佳答案

CodeIgniter 中的 session 值

The documentation表示如果你想从 session 中提取一个值,你应该使用以下语法:

$this->load->library("session");
/*...*/
$userid = $this->session->userdata("userid");

Doctrine 中的 WHERE 子句

根据DQL Documentation ,我们只需要将其修补到您的 where 语句中:

->where("m.account_id = ?", $userid)

关于php - 如何在 DQL CodeIgniter 中传递变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1947324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com