【发布时间】:2014-11-20 00:34:33
【问题描述】:
使用 CodeIgniter,我有几个自定义控制器:
- MY_Controller - 这扩展了 CI_Controller
- Front_Controller - 扩展 MY_Controller,用于任何面向“用户”的页面
- Admin_Controller - 扩展 MY_Controller,用于“管理”页面
现在,当我在管理“索引”页面上时,其控制器使用 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_控制器
<?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');
}
}
【问题讨论】:
-
我们可以看看一些代码吗?
-
TBH 我不知道该给你看什么!
-
你的 MY_Controller 是什么样子的?
-
你从 Front_Controller 得到了什么样的错误?
-
错误是关于未设置的变量。事情是,Front_Controller 没有被 be 调用,所以不应该出现错误(我知道,我还是要修复它们,但仍然......)
标签: php codeigniter