[eluser]Unknown[/eluser]
Hi.
I can't get the instance in the post controller hook. Here is my Sourcecode.
Code:
// config/autoload.php
$autoload['libraries'][] = 'MY_Controller';
// config/hooks.php
$hook['post_controller'][] = array(
'class' => 'MY_Controller',
'function' => 'test',
'filename' => 'MY_Controller.php',
'filepath' => 'libraries'
);
// controllers/welcome.php
class Welcome extends MY_Controller {
function Welcome() {
parent::MY_Controller();
}
function index() {
$this->view['var1'] = 'var1';
}
}
// libraries/MY_Controller.php
class MY_Controller extends Controller {
var $view=array();
function MY_Controller() {
parent::Controller();
}
function test() {
$this->CI =& get_instance();
print_r($this->CI->view);
}
}
// OUTPUT
Array ( )
If i try to use $this->view the output is empty too.
Code:
// libraries/MY_Controller.php
function test() {
print_r($this->view);
}
// OUTPUT
Array ( )
If i use global $CI the output is right.
Code:
// libraries/MY_Controller.php
function test() {
global $CI;
$this->CI = $CI;
print_r($this->CI->view);
}
// OUTPUT
Array ( [var1] => var1 )
What's the problem? How can i get rid of the "global $CI"? Can anyone help?
Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.9
I tested the same on my Linux Server with Apache 2.2 and PHP4 and there is the get_instance version working...
Greetings,
Wolfgang