從@ 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) –