[eluser]yesiwill[/eluser]
Hi
We have a website based on PHPNUKE and we've developed some modules for it using 'straight' PHP. Since the very first glance of CI, we've decided to try it out in our new modules. However, we can't afford the time to 'transfer' the whole website to CI, so I've been thinking that if there is a way to introduce CI to the existing website without disturbing the codes that works well so far.
The idea which comes out is like this: we give CI some wrapper codes in order to meet the requirement of modules in PHPNUKE. In these codes, we just simply
include or
require index.php of CI to do the initializtion. After that, our main work is to call the proper controller, right? I have 2 methods to do this:
METHOD 1
$former_url = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = '/career_test/display_obj';
require_once("CI/index.php");
$_SERVER["REQUEST_URI"] = $former_url;
METHOD 2
$former_url = $_SERVER['REQUEST_URI'];
$_SERVER['REQUEST_URI'] = '/';
require_once("CI/index.php");
require_once("CI/system/application/controllers/career_test.php");
$controller = new Career_test();
$controller->display_obj();
$_SERVER["REQUEST_URI"] = $former_url;
In method 1, we cheat CI by providing an uri instead of explorer(Need to modify $config['uri_protocol'] in config.php first).
In method 2, we firstly keep the default controller(like welcome.php) silent, and then call the controller myself.
However, in this 'simply require' solution I found that the scope of automatically initialized objects(such as $BM, $OUT) in /codeigniter/CodeIgniter.php had changed.
For example, there is '$OUT->_display();' in row 255 of /codeigniter/CodeIgniter.php to display the output. After reading /libraries/Output.php, We can find that $BM and $CFG are used in the member function _display(). Although both of them are declared
global in the function, they still can not be used here, the error report says "Fatal error: Call to a member function elapsed_time() on a non-object in /usr/local/apache2/htdocs/public/CI/system/libraries/Output.php on line 185".
The same thing happens after the controller is called and about to display views, where $OUT is declared global but still gets a 'non-object' error.
I was
wondering what's the different between accessing index.php through explorer and simply requiring it in the code, especially the global scope of var.
Any comment or suggestion will be highly appreciated.
Thanks