自定义控制器在不应该被调用时被调用

时间:2014-09-25 09:33:47

标签: php codeigniter

使用CodeIgniter,我有一些自定义控制器:

  • MY_Controller - 这扩展了CI_Controller
  • Front_Controller - extednds MY_Controller,用于任何面向页面的“用户”
  • Admin_Controller - 扩展MY_Controller,用于“admin”页面

现在,当我在admin“index”页面上,其控制器使用Admin_Controller时,我收到来自Front_Controller的记录错误。

我把一个var_dump()放到Front_Controller中,我在管理页面上看不到它,所以我确信它不会被我的代码调用,但不知何故,它确实被调用了!

对此有任何解释吗?

一些代码:

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
    );
}
}

管理员指数:

<?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 个答案:

答案 0 :(得分:0)

据我所知,CodeIgniter是singleton,所以它会在每个请求中加载所有内容。
这意味着即使没有调用,Front_Controller也会被加载。所以,如果有错误,他们就会出局。

花一些时间,修复错误,一切都应该好。