Yeah, just add the by reference operator to the param (&).
function sessions_end(&$session)
{
echo "Your member ID is ".$session->userdata['member_id'];
}set_flashdata is a available, but set_userdata is not
$session->set_flashdata('custom_variable', 'yes');
$session->userdata['custom_variable'] = 'yes';As a follow on to this - I’m trying to access the logger library to post to the Control Panel Log on sessions_end for a project, but no matter which way I try to load the library / post an item, I get various errors in the CI Log.
Is it possible to reference the logger in the sessions_start/sessions_end hook?
As a follow on to this - I’m trying to access the logger library to post to the Control Panel Log on sessions_end for a project, but no matter which way I try to load the library / post an item, I get various errors in the CI Log. Is it possible to reference the logger in the sessions_start/sessions_end hook?
Can you post your code and error message?
Hi Erik,
Sorry for my delay in replying - been out of the office.
I’ve tried various combinations, based on your article on using the log:
function start_process(&$OBJ) {
$this->EE = $OBJ;
$this->EE->load->library(‘logger’); $this->EE->logger->log_action(“Testing new CP log item”);
}
and many other combinations of the $OBJ-> or $this-> etc to no avail.
Most of the errors I’m getting are various types of “Call to undefined method”.
Cheers,
Carl.
Carl,
You’re using a sessions hook so the object being passed to you is not the EE super object but rather the session object.
You’ll want to use the get_instance() function in your __construct() method and reference the EE super object that way to load and use the log class.
Make sense?
Just as a follow up….
I’ve created the __construct() function as follows:
function __construct() { $this->EE =& get_instance(); }
and then within the function
function send_process(&$OBJ) { $this->EE->load->library(‘logger’); $this->EE->logger->log_action(“Testing Testing 123”); }
However, I’m getting the following error:
Severity: Notice –> Undefined property: Addons_extensions::$session /home/clients/public_html/sandbox/system/expressionengine/libraries/Logger.php 62
Carl,
Since you’re within one of the sessions hook, the session object isn’t actually available within the EE object. This presents an interesting challenge since the log_action() method is referring to the session object.
I’m not sure of the plausibility of this and I also don’t know what it could hurt without further investigation - BUT - this should work:
EE->session =& $OBJ;
$this->EE->load->library('logger');
$this->EE->logger->log_action('Testing Testing 123');
unset($this->EE->session);
}
?>I have the unset() function in there just because I haven’t thought through any negatives to defining the EE session object from within the extension hook. Probably best you get a product developer to peek at this as well (Greg, Pascal, Wes etc)
Just a note incase anyone else is head scratching wondering why @rsan’s example doesn’t work…
If you have Low Seg2Cat installed, that has priority 1 set and any other extensions using the same sessions_end hook will result in “Trying to get property of non-object” warnings.
I knocked the priority of Low’s extension down to 10 and all worked as described above.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.