2012-08-01 43 views
1

我試圖使用$ this-> load-> add_package_path向我的CI應用程序添加一個新的子應用程序。我可以看到如何使用這個觀點和如此:只要把對代碼點火控制器使用add_package_path

$this->load->add_package_path("/mypackage"); 

在控制器ctor。不幸的是,這並沒有幫助,因爲我想從包路徑中找到控制器:它看起來像雞與雞蛋問題。有沒有其他地方我可以把一個add_package_path調用(如index.php)?

回答

0

通過追蹤通過CI來找出它。原來你不能這樣做。你可以把你自己的控制器中/應用/控制器的子目錄,但你不能把它們放在別的地方:特別是作爲http://codeigniter.com/user_guide/libraries/loader.html意味着,

這些元素可以是庫(類)視圖文件,助手,模型,或者你自己的文件。

「您自己的文件」不包括控制器。通過對CodeIgniter.php和Router.php進行更改,我最終能夠通過APPPATH查看環境設置。不過,我不喜歡做這種改變,所以我退出了這些改變。我會把它放在這裏以防別人從中受益。

Router.php變化:

function _validate_request($segments) 
{ 
... 
    // Does the requested controller exist in the root folder? 
    if (file_exists(APPPATH.'controllers/'.$segments[0].'.php') 
     || file_exists(ENVIRONMENT.'/controllers/'.$segments[0].'.php')) // New bit here 
    { 
    return $segments; 
    } 
.... 
} 

CodeIgniter.php變化,「四圍行246:

if (! file_exists(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php')) 
{ 
    // New bit here 
    if (! file_exists(ENVIRONMENT.'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php')) 
    { 
    show_error('Unable to load your default controller. Please make sure the controller specified in your Routes.php file is valid.'); 
    } 
    include(ENVIRONMENT.'/controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'); 
} else { 
    include(APPPATH.'controllers/'.$RTR->fetch_directory().$RTR->fetch_class().'.php'); 
} 
相關問題