CodeIgniter Forums

Full Version: Using $this->library_name-> in 404 error page cause error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Unknown[/eluser]
I'm using a custom 404 page:

routes:
Code:
$route['404_override'] = 'errors/page_not_found';

errors class:
Code:
class Errors extends CI_Controller {

public function page_not_found() {

  $data = array(
   'page' => '404_view',
   'meta_title' => 'Pagina non trovata'
  );
  
  $this->output->set_status_header('404');
  $this->load->view('template', $data);

}

}

In my template I use this to check the user is logged (the session class is autoloaded):
Code:
if ($this->session->userdata('logged'))

When I try to access a non-existant function inside a controller (like for example /events/asd) this error appears:

Code:
Message:  Undefined property: CI_Loader::$session

when I try to access a non-existant controller (/asd) everything is ok.

The same error appear when I use my custom libraries.

I think the error is caused by the scope of the variable $this, what should I do?