rayrayrugby Posted October 29, 2014 Share Posted October 29, 2014 Hi everybody, I'm currently trying to get the id of the current employee from an outside php file. I did it like that but it doesn't work : <?php require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../config/settings.inc.php'); require_once(dirname(__FILE__).'/../../classes/Cookie.php'); $cookie = new Cookie('psAdmin'); $id_employee = $cookie->id_employee; $profile = $cookie->profile; echo $id_employee; echo $profile; die(); ?> Could somebody help me please ? Link to comment Share on other sites More sharing options...
cristic Posted October 29, 2014 Share Posted October 29, 2014 You should use Context object. <?php require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../config/settings.inc.php'); $context = Context::getContext(); if (isset($context->employee) && $context->employee->id > 0) { $id_employee = $context->employee->id; echo "ID Employee: $id_employee"; } else echo "No employee logged in."; die(); ?> 1 Link to comment Share on other sites More sharing options...
rayrayrugby Posted October 29, 2014 Author Share Posted October 29, 2014 Thanks for your reply cristic, I tried using Context but my variable $id_employee is still set to 0 instead of 1 ... 1 Link to comment Share on other sites More sharing options...
ZiedDams Posted January 12, 2022 Share Posted January 12, 2022 On 10/29/2014 at 4:29 PM, cristic said: You should use Context object. <?php require_once(dirname(__FILE__).'/../../config/config.inc.php'); require_once(dirname(__FILE__).'/../../config/settings.inc.php'); $context = Context::getContext(); if (isset($context->employee) && $context->employee->id > 0) { $id_employee = $context->employee->id; echo "ID Employee: $id_employee"; } else echo "No employee logged in."; die(); ?> i try it this code but t give me no employee login in while im logged in , any idea ? Link to comment Share on other sites More sharing options...
Ress Posted March 5, 2022 Share Posted March 5, 2022 (edited) You should load also the init.php file, like confing.php and settings.php Edited March 5, 2022 by Ress (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now