从@ wolfgang1983 Ben Swinburne一个答案在这里结合原来的答案:从Atiqur Rahman Sumon
您可以包含任何目录index.php
,但是,您需要更改$system_path
和$application_folder
变量的相对匹配位置。那么如果你想彻底改变你的整个应用程序的路径,那就太好了,但我不想,所以我只是将index.php
文件复制到我需要包含codeigniter的目录中。
ROOT/
.. /application
.. /system
.. /includes
.. /Events.php <- I need access from here
.. /index.php <- Copied CI index with new paths
.. /index.php
在/includes/index.php
:
//$system_path = 'system';
$system_path = '../system';
//$application_folder = 'application';
$application_folder = '../application';
现在,您可以与您的文件笨:
<?php
ob_start();
include('index.php');
ob_end_clean();
$CI =& get_instance();
$CI->load->library('session'); //if it's not autoloaded in your CI setup
echo $CI->session->userdata('name');
?>
如果你现在刷新页面,你会结束与默认控制器加载。
因此,从Atiqur Rahman Sumon的回答中,我们可以定义一个常量,以告诉默认控制器我们想要跳过它的正常调用堆栈。
ob_start();
define("REQUEST", "external"); <--
include('index.php');
ob_end_clean();
而在你default_controller.php
:
function index()
{
if (REQUEST == "external") {
return;
}
//other code for normal requests.
}
[从外部文件访问笨会话值]的可能的复制(HTTP:/ /stackoverflow.com/questions/7926455/access-codeigniter-session-values-from-external-files) –