Codeigniter 扩展CI_控制器/间接修改重载属性

Codeigniter 扩展CI_控制器/间接修改重载属性,codeigniter,continuous-integration,php,Codeigniter,Continuous Integration,Php,CI社区似乎对此没有答案(或者可能很明显,这看起来像一个noob问题?),所以我在这里问 我已经看到这种错误很长一段时间了(错误消息如下),但我一直使用。现在我不想再编辑核心CI代码了,我知道必须有一个优雅的解决方案 这是设置 在我的application/config/routes中 $route['default_controller'] = "dispatcher"; application/Controller/中的Dispatcher类定义如下: class Dispatcher e

CI社区似乎对此没有答案(或者可能很明显,这看起来像一个noob问题?),所以我在这里问

我已经看到这种错误很长一段时间了(错误消息如下),但我一直使用。现在我不想再编辑核心CI代码了,我知道必须有一个优雅的解决方案

这是设置

在我的application/config/routes中

$route['default_controller'] = "dispatcher";
application/Controller/中的Dispatcher类定义如下:

class Dispatcher extends MY_Controller {

 function __construct() {
  parent::__construct();
  $this->load->helper(array('form','https'));
 }


 function index() {

  # load models
  $this->load->model('site/map');
  $this->load->model('site/langs');
  $this->load->model('site/pages');
  if ( $mapped = $this->map->get_map() ){ // this is the line 21
   $this->langs->set_user_lang( $this->GLO['show_lang_in_url'], $this->GLO['show_lang_at_home'] );
   $red = base_url().$this->GLO['user_lang_label']."/".$mapped;
   redirect($red, "refresh");
   } 

  ...
现在,MY_控制器位于application/core中,定义如下:

class MY_Controller extends CI_Controller {

 public function __construct() {
        parent::__construct();
  $this->GLO = array();   

  #
  # set defaults:
  #
  $this->GLO['deb'] = '';
  $this->GLO['baseurl'] = base_url();
  ... (more GLO[key] = value ) 
}

 public function __set ($key, $value ) {
  $this->GLO[$key] = $value;
 }
我使用的每个模型都是这样开始的(相应地命名):

现在,使用Debian上的CI 2.1.2、PHP 5.3.3和Apache 2,在尝试加载页面时,我遇到以下错误:

遇到PHP错误严重性:注意消息:间接 修改重载属性Langs::$GLO无效 文件名:site/langs.php行号:82

遇到PHP错误严重性:注意消息:未定义 属性:Dispatcher::$map文件名:controllers/Dispatcher.php行 电话:21

致命错误:对中的非对象调用成员函数get_map() /home/webdev/MC/_WWW/application/controllers/dispatcher.php,第21行

第21行是地图模型中上面标记的那一行

if ( $mapped = $this->map->get_map() ){
另一个模型中的第82行如下所示:

$this->GLO['langs'][] = $temp;
在整个代码中,此GLO数组被引用为$this GLO[key]。它必须不时读写。如果删除\u控制器中的\u set函数,则会收到更多此类警告

问题在哪里


提前多谢

我不确定第一个错误是什么-但这两个:

遇到PHP错误严重性:注意消息:未定义 属性:Dispatcher::$map文件名:controllers/Dispatcher.php行 电话:21

致命错误:对中的非对象调用成员函数get_map() /home/webdev/MC/_WWW/application/controllers/dispatcher.php,第21行

…看起来您没有正确加载模型

改变

if ( $mapped = $this->map->get_map() ){


在application/models/下有一些子文件夹,其中一个是类文件所在的“site”。对于CI文档,此语法实际上应该是正确的。尝试将“映射”移动到“模型”的根,看看会发生什么?你确定你的文件都是小写的吗?好吧,它适用于以前版本的CI和一些实时站点。正如我所说的,如果我修改核心CI代码中的一行代码,这一切都会完美工作。这就是我想最终停止做的,因此问题是……修改是否解决了关于“地图”的两个错误?地图在修改后真的能工作吗?是的,我所指的修改很好,不会抛出任何错误。
if ( $mapped = $this->map->get_map() ){
$this->load->model('map');
if ( $mapped = $this->map->get_map() ){