[eluser]maikens[/eluser]
I am in the process of trying to debug a problem in my application where users are being logged out unexpectedly. I took it as an opportunity to configure the email aspect of the app as well. What I am trying to do is set up my application so that whenever a session is destroyed, I'll get an email with a dump of the session userdata, and the debug_backtrace(). It's not the best method, but it's a start
My problem is that when I logout (and thus destroy the session), I get an error saying that the $email variable is undefined in the controller (even though I'd already autoloaded it).
The error is:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Dashboard::$email
Filename: libraries/MY_Session.php
Line Number: 43
MY_Session:
Code:
// ...
function sess_destroy() {
parent::sess_destroy();
ob_start();
echo 'Userdata before destruction:';
var_dump($this->userdata);
echo 'Debug backtrace:';
var_dump(debug_backtrace());
$msg = ob_get_clean();
$ci =& get_instance();
$ci->email->send('[email protected]', 'user@example', 'Session destroyed', $msg);
$this->userdata = array();
}
// ...
MY_Email:
Code:
class MY_Email extends CI_Email {
/**
* Constructor
*/
public function __construct($config) {
parent::__construct($config);
// todo: initialization, etc to go here
}
/**
* Overrides the existing CI Email send function to perform some extra actions
* before doing the actual send
*
* @param mixed $from a string, or an indexed or associative array. Can contain to and reply_to addresses/names
* @param mixed $recipients a string or associative array. Can contain to, cc, and bcc addresses
* @param string $subject the subject of the email
* @param mixed $body a string or associative array. Can contain html and text email bodies
* @param array $headers contains any email headers you wish to explicitly set
* @param array $attachments contains paths to files to attach to the email
* @return bool whether the email was successfully sent
*/
public function send($from, $recipients, $subject, $body, $headers = array(), $attachments = array()) {
$this->clear(); // clear any parameters from previous calls to send()
// From and reply_to address
if(is_array($from)) {
if(isset($from['from'])) {
$this->from($from['from'][0], $from['from'][1]);
$this->reply_to($from['reply_to'][0], $from['reply_to'][1]);
}
else $this->from($from[0], $from[1]);
}
else $this->from($from);
// Handle recipients (to, cc, bcc)
if(is_array($recipients) && isset($recipients['to'])) {
$this->to($recipients['to']);
$this->cc($recipients['cc']);
$this->bcc($recipients['bcc']);
}
else $this->to($recipients);
// Handle subject
$this->subject($subject);
// Handle setting html and text email bodies
if(is_array($body)) {
$html = $this->html_template($body['html'], $subject);
$this->message($html);
$this->set_alt_message(strip_tags($body['text']));
}
else $this->message(strip_tags($body)); // assume text-only email
// Handle setting mail headers
if(!empty($headers)) {
foreach($headers as $key => $value) $this->set_header($key, $value);
}
// Handle attaching files
if(!empty($attachments)) $this->attach_files($attachments);
return parent::send();
}
// ...
Anyone have any idea why this is happening?