views:

120

answers:

1

i got a question in DQL how to pass session User 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″‘)

i want to show data according to current logged user.

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

this is not working

+2  A: 

Session Values in CodeIgniter

The documentation indicates that if you wish to extract a value from the session, you ought to use the following syntax:

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

WHERE Clause in Doctrine

According to the DQL Documentation, we need only patch that into your where statement:

->where("m.account_id = ?", $userid)
Jonathan Sampson
I m getting doctrine Error $userid = $this->session->userdata("user_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=$userid') ->execute();
ansh
after adding ->where("m.account_id = ?", $userid);i m getting Parse error
ansh
Make sure you have a valid reference to `session` before trying to use `$this->session`
Jonathan Sampson
i changed it to ->where('m.account_id = ?', $userid);
ansh
tht workgin when i m adding using same to add current logged user idbut not inside DQL
ansh
Is your session library loaded, Ansh?
Jonathan Sampson
Yes i m able to add User_id from Session to mysql.using this $u->account_id = Current_User::user()->id;
ansh
->where('m.account_id = ?','$userid'); i tried this is also not working as shown in Documentation.
ansh
i m getting phrase error in ->execute(); line
ansh
Solved I need to remove ; in WHERE lol Thanks Alot Jonathan u always help me :) Have a nice day
ansh
Congratulations, Ansh. Good work!
Jonathan Sampson