CI コミュニティはこれに対する回答を持っていないようです (または、あまりにも明白すぎて初歩的な質問のように見えますか?) ので、ここで質問します。
この種のエラーは長い間見られてきましたが (エラー メッセージが続きます)、常にこの「汚い」回避策を使用してきました。今はもうコア CI コードを編集したくありません。これには適切な解決策が必要であることはわかっています。
これがセットアップです。
私のapplication/config/routesにはこれがあります
$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;
}
CI 2.1.2、PHP 5.3.3、Debian 上の 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 関数を削除すると、これらの警告がさらに表示されます。
問題はどこだ?
よろしくお願いします!