Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] Need Help with my Error Controller
#1

[eluser]Unknown[/eluser]
Hi there,

I am developing a project using the latest version of codeigniter. In my routes.php I went ahead and re-routed my 404 error to a custom controller action
Code:
$route['404_override'] = 'error/not_found';

The error controller, in its entirety:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Error extends FTS_Controller {

public function __construct()
{
  parent::__construct();
}

public function index()
{
  $this->report['error'] = 'An unexpected error occured!';
  
  $this->load->view('header');
  $this->load->view('error/index');
  $this->load->view('footer');
}

public function not_found()
{
  // 404
  $this->output->set_status_header('404');
  $this->load->view('header');
  $this->load->view('error/404');
  $this->load->view('footer');
}

public function not_logged_in()
{
  $this->load->view('header');
  $this->load->view('error/not_logged_in');
  $this->load->view('footer');
}
}

Notice I am not using the regular "CI_Controller" as a base class, instead I am using my own, which looks like this

Code:
class FTS_Controller extends CI_Controller {
function __construct()
{
  parent::__construct();
  
  // $this->load->model('User'); AUTOLOADED
  $this->loggedIn = false;
  $this->loggedIn = $this->LoginModel->isLoggedIn(); //This is line thirteen, I removed some comments so its easier to read.
  
  if ($this->loggedIn)
  {
   $this->user = $this->User->populate($this->session->userdata('id'));
   $this->notificationCount = $this->NotificationsModel->numberOfNotifications($this->user['id']);
  }
  
  //Get current time for benchmarking purposes...
  $this->execStartTime = microtime(true);
}
}

This all works fine and correct. If you go to http://www.mywebsite.com/thisdoesnotexist, the appropriate view is loaded and I get the 404 error page I created. However, if you go to something like http://www.mywebsite.com/home/thisdoesnotexist it errors out. Note that "home" is an actual controller that exists, however the function "thisdoesnotexist" does not exist in that controller. That is where my problem is, it seems as if the error controller only handles 404s for controllers, not actions of controllers as well...

This is the error I get when I go to something like /home/adflkjakd

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Siteerror::$LoginModel

Filename: core/FTS_Controller.php

Line Number: 13


Fatal error: Call to a member function isLoggedIn() on a non-object in C:\xampplite\htdocs\FTS_3_0\application\core\FTS_Controller.php on line 13

I first thought that maybe it would work if I just used the original CI_Controller class for the error controller, but changing FTS_Controller to CI_Controller didn't help. I then thought that maybe "error" was a reserved name, so I changed the controllers name to siteerror, and that didn't help either...

If any of you have any idea as to what is wrong, I'd highly appreciate it. I've been stuck on this error for about 3 days now...




Theme © iAndrew 2016 - Forum software by © MyBB