0
votes

Using CodeIgniter, I have a few custom controllers:

  • MY_Controller - this extends the CI_Controller
  • Front_Controller - extednds MY_Controller, used for any "user" facing pages
  • Admin_Controller - extends MY_Controller, used for "admin" pages

Now, when I am on the admin "index" page, the controller of which uses Admin_Controller, I am getting logged errors coming from the Front_Controller.

I put a var_dump() into the Front_Controller and I cannot see it on the admin page, so I'm confident it is not being called by my code, but somehow, it does seem to be getting called!

Is there any explanation for this?

Some code:

Admin_Controller

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Admin_Controller extends MY_Controller
{
public function __construct() {
    parent::__construct();

    if(!$this->ion_auth->logged_in()) {
        redirect('login', 'location');
    } elseif($this->ion_auth->logged_in() AND !$this->ion_auth->in_group(array('admin', 'mod'))) {
        redirect('account/dashboard', 'location');
    } else {
        $this->user = $this->ion_auth->user()->row();
    }

    $this->data = array(
        'head' => 'inc/head',
        'foot' => 'inc/foot',
        'nav' => 'admin/inc/nav',
        'flash' => 'inc/flash_messages',
        'user' => $this->user
    );
}
}

Admin index:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Index extends Admin_Controller {

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

public function index()
{
    $this->load->vars($this->data);
    $this->load->view('admin/index');
}

}

MY_Controller

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    class MY_Controller extends CI_Controller
    {
        public function __construct() {
            parent::__construct();

            $this->data = array(
                'head' => 'inc/head',
                'foot' => 'inc/foot',
                'nav' => 'inc/nav',
                'flash' => 'inc/flash_messages',
            );

            $this->load->model('new/resellers/reseller_model');
            $this->load->model('new/white_labels/white_label_model');

            // find matching domain and show logo
            $domain = $_SERVER['SERVER_NAME'];
            $reseller = $this->reseller_model->get_by('domain', $domain);
            if($reseller):
                $resellerWhiteLabel = $this->white_label_model->get($reseller->white_label_id);
                if($resellerWhiteLabel):
                    $this->data['portal_reseller'] = $reseller;
                    $this->data['portal_reseller_white_label'] = $resellerWhiteLabel;
                endif;
            endif;

            $this->load->library('lib_log');
            $this->load->library('ion_auth');

            $this->load->helper('language');
            $this->lang->load('auth');
            $this->lang->load('site');
        }
    }
1
can we see some code? - Rooneyl
TBH I don't know what to show you! - Mr Pablo
What does your MY_Controller look like? - Rooneyl
What kinds of errors are you getting from the Front_Controller? - Rooneyl
The errors are about variables not being set. Thing is, the Front_Controller has not been called by be, so the errors shouldn't appear (I know, I am going to fix them anyway but still...) - Mr Pablo

1 Answers

0
votes

As far as I can remember CodeIgniter is a singleton, so it loads everything on each request.
This means that the Front_Controller will get loaded even if not called. So if there are errors in it they will out.

Take some time, fix the errors and all should be good.