What would be the easiest way to include a CI file? Let's say I want to include http://example.com/ci/index.php/mycontroller/ on example.com
example.com doesn't run CI and I can't do include('ci/index.php/mycontroller').
What would be the easiest way to include a CI file? Let's say I want to include http://example.com/ci/index.php/mycontroller/ on example.com
example.com doesn't run CI and I can't do include('ci/index.php/mycontroller').
Assuming you have PHP configured to allow url includes, just...
include('http://example.com/ci/index.php/mycontroller/');
(Requires PHP 4.3.0+)
Depending on what you want to do the output, you should be able to set the REQUEST_URI
or whatever CI uses for determining the request and then just include the bootstrap file...
EDIT: Actually, I think it would be better to go the other way around, if that's possible (again, that depends on what exactly you want to do - so please tell us). What I mean is create a CodeIgniter controller that simply includes your script...
If you want to simply display the output of the CI script, you could open the URL, read the contents and output them - or use readfile()
. From the stand point of the CI app, the request would be coming from the including server (not the end user), and to pass cookies/session vars along would require using something like cURL.
If you actually want to include the source code, that is possible, but a security risk. There are a few SO questions about this topic:
They note (among other things) that to include the source you'll need to make sure the CI site does not execute the page, but simply outputs the contents of the php file, and that actually including code from a URL is amazingly dangerous.
You're essentially trusting the included site (and all the servers the request goes through) to provide (good) code that the including server will then execute without question.
As I couldn't seem to invoke the CI controller's functions, I decided it's easiest to simply load the page with jQuery:
$('#myDiv').load('ci/index.php/mycontroller', {}, function(){
$('#myDiv #loading').hide();
$('#myDiv #data').slideDown(500);
});