我在 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/