How to include CodeIgniter generated pages?

╄→尐↘猪︶ㄣ 提交于 2020-01-03 17:16:13

问题


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').


回答1:


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);
});



回答2:


Assuming you have PHP configured to allow url includes, just...

include('http://example.com/ci/index.php/mycontroller/');

(Requires PHP 4.3.0+)




回答3:


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:

  • Including a remote file in PHP
  • PHP: Any logical use cases for include/requiring remote source files?

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.




回答4:


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...



来源:https://stackoverflow.com/questions/1828250/how-to-include-codeigniter-generated-pages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!