1

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

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

这是设置。

在我的应用程序/配置/路由中,我有这个

$route['default_controller'] = "dispatcher";

application/controllers/ 中的 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_Controller 位于 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;
 }

我使用的每个模型都是这样开始的(相应地命名):

class Map extends CI_Model {

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

 function get_map(){
        .....
        return true;
        }

现在在 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

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

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

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

另一个模型中的第 82 行如下所示:

$this->GLO['langs'][] = $temp;

在整个代码中,这个 GLO 数组被称为 $this-GLO[ key ]。它必须不时地阅读和写入。如果我删除 MY_Controller 中的 __set 函数,我会收到更多警告。

问题出在哪里?

提前非常感谢!

4

1 回答 1

0

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

遇到 PHP 错误 严重性:通知消息:未定义属性:Dispatcher::$map 文件名:controllers/dispatcher.php 行号:21

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

...看起来你没有正确加载你的模型?

改变

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

$this->load->model('map');
if ( $mapped = $this->map->get_map() ){
于 2012-09-13T15:47:01.477 回答