Session data available in MY_Log? |
[eluser]ThatAirplaneGuy[/eluser]
I would like to attach some information from the current user session with every log_message that is created. Example: I have username stored in the session, I would like to attach that username to every error log entry that is created under that user's session. I tried creating the MY_Log in /libraries below: Code: <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); I get the error that it can't access $session. It looks like the session isn't available. Is what I'm looking for possible with CI? Thanks.. Edit: Here is the actual error message(s): Code: Notice: Undefined property: MY_Log::$session in E:\Web\myapp\application\libraries\MY_Log.php on line 37
[eluser]Aken[/eluser]
You're running into two problems here: 1) You can't use $this->session in your Log library, because it does not extend the CI superobject like a controller or model. You'll need to use get_instance() as explained in Utilizing CodeIgniter Resources within Your Library. 2) The Log library is used many times both before the CI superobject exists, and before any libraries are autoloaded to that CI object. So you need to check if both exist before trying to access them, or you'll get errors. Try something like this: /application/libraries/MY_Log.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]ThatAirplaneGuy[/eluser]
Excellent! Sorry for the delayed response - got pulled off onto another project for a couple of days. Thanks again for the solution! CJ |
Welcome Guest, Not a member yet? Register Sign In |