使用多個 application ,需要怎麼調整 index.php
看到了使用多個 application 的討論出處是
http://codeigniter.com/forums/viewthread/44568/
他可以將檔案結構變成 ↓
/{domain_root}
/application
/admin
/config
/controllers
/models
/scripts
/public
/config
/controllers
/models
/scripts
...
/library
/helpers
/init
/libraries
/plugins
...
/system
/helpers
/init
/libraries
/plugins
...
/www
/css
/img
index.php
/js
但是他分享的 index.php 我看不太懂
index.php
define('EXT', '.'.pathinfo(__FILE__, PATHINFO_EXTENSION));
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
define('BASEPATH', dirname(dirname(__FILE__)).'/system/';
define('APPPATH', dirname(BASEPATH).'/application/');
define('LIBPATH', dirname(BASEPATH).'/library/'
require_once BASEPATH.'codeigniter/CodeIgniter'.EXT;
官方多個 application 的方法是
http://codeigniter.org.cn/user_guide/general/managing_apps.html
index.php 修改這個就好
$application_folder = "application/foo";
但我希望利用 URI 去切換 app ,用官方的方法沒辦法他是直接寫死在 index.php 裡面
上面兩種方法都達不到我的目的
我希望我的檔案結構是↓
/mysite
/application
/admin
/config
/controllers
/models
/scripts
/public
/config
/controllers
/models
/scripts
...
然後我在網址呼叫的時候
/mysite/admin/index.php/welcome就使用 admin 的 app
/mysite/public/index.php/welcome就使用 public 的 app
這樣子似乎
$application_folder 需要動態的抓取 URI 輸入的是 admin 或是 public
才知道要切換哪一個 app
不知道這樣的話
index.php 是要修改哪一段才可以利用 URI 就自動切換 app 呢 ? 我认为应该用 url rewrite 来实现。
现在 ci 中国的 user_guide 就是用 rewrite 实现的两个 app,根目录是一个,/user_guide 是另一个 app
实际上就是不同 url 转到不同的文件上。 現在我用一個比較直覺的方法去分多個 application
不過總感覺應該有問題,好像沒有這麼簡單
1. 與 system 同層下建立 app1 , app2
2. 將 system 裡面的 application 各複製一份到 app1 , app2
3. 與 system 同層的 index.php 各複製一份到 app1 , app2
4. 修改 app1 的 index.php
$system_folder = "../system";
$application_folder = "../app1/application";
修改 app2 的 index.php
$system_folder = "../system";
$application_folder = "../app2/application";
5. 測試
網站/app1/index.php/welcome/index
網站/app2/index.php/welcome/index
6. 更新 CI 只要蓋過 system 就好 app1 , app2 不用更動
其實現在都還沒開始開發
都還在測這些架構上的想法而已
只是直覺上就覺得好像會有問題
路徑上或是什麼之類我也不清楚
因為經驗不夠所以如果有什麼意見的話
一起交流一下
感謝 重写下 APPPATH 呗 回复 4# z445619791
我發現沒改 APPPATH 但可以跑
好像是一開始 is_dir 判斷後就直接將 'APPPATH' 設定為 $application_folder = "../app1/application";
看來是誤打誤撞成功的
if (is_dir($application_folder))
{
define('APPPATH', $application_folder.'/');
}
else
{
if ($application_folder == '')
{
$application_folder = 'application';
}
define('APPPATH', BASEPATH.$application_folder.'/');
}
页:
[1]