Welcome Guest, Not a member yet? Register   Sign In
Integrate CI with existing websites
#1

[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
#2

[eluser]yesiwill[/eluser]
Any idea?
#3

[eluser]Jamie Rumbelow[/eluser]
What you could do is, set up the CI install and plugin on a HTTP accessible part of your server (/var/www) and then use file_get_contents("http://yourserver.com/ci/controller/function/any/variables/here");

The server should output any content like normal...
#4

[eluser]yesiwill[/eluser]
[quote author="Jemgames" date="1221177640"]What you could do is, set up the CI install and plugin on a HTTP accessible part of your server (/var/www) and then use file_get_contents("http://yourserver.com/ci/controller/function/any/variables/here");

The server should output any content like normal...[/quote]

Thanks soooooo much. It really helps me a lot. It works.
But I still want to know why require() gets the scope of global changed. I can not use global var in the member functions of any class after I require("index.php").

Thanks again.




Theme © iAndrew 2016 - Forum software by © MyBB