CodeIgniter Forums
Using $this->library_name-> in 404 error page cause error - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using $this->library_name-> in 404 error page cause error (/thread-45529.html)



Using $this->library_name-> in 404 error page cause error - El Forum - 09-25-2011

[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?