標籤:style blog http color 使用 os 檔案 io
前台入口檔案index.php
<?php//前台入口define(‘THINKPHP_PATH‘, ‘../ThinkPHP/‘);//底層的位置define(‘APP_PATH‘, ‘./home/‘);//定義項目位置define(‘APP_DEBUG‘, true);//定義DEBUG開關require_once THINKPHP_PATH.‘ThinkPHP.php‘;//echo ‘hellow‘;?>
設定檔:
1 <?php2 return array(3 //‘配置項‘=>‘配置值‘4 ‘DEFAULT_C_LAYER‘ => ‘Controller‘, // 預設的控制器層名稱5 ‘URL_MODEL‘ => 1, // URL訪問模式,選擇性參數0、1、2、3,代表以下四種模式:6 );7 ?>
Controller下的IndexController.class.php檔案:
1 <?php2 namespace Home\Controller;3 use Think\Controller;4 class IndexController extends Controller {5 public function index(){6 echo "hello world";7 }8 }
瀏覽器調試結果:
這個路徑http://localhost:8080/test/index.php是可以顯示控制器方法中的歡迎資訊的,
而http://localhost:8080/test/index.php/index和http://localhost:8080/test/index.php/index/index卻提示了錯誤資訊
:(
無法載入模組:Index錯誤位置
FILE: C:\wamp\www\ThinkPHP\Library\Think\Dispatcher.class.php LINE: 172
TRACE
#0 C:\wamp\www\ThinkPHP\Library\Think\Dispatcher.class.php(172): E(‘???????????????...‘)
#1 C:\wamp\www\ThinkPHP\Library\Think\App.class.php(36): Think\Dispatcher::dispatch()
#2 C:\wamp\www\ThinkPHP\Library\Think\App.class.php(184): Think\App::init()
#3 C:\wamp\www\ThinkPHP\Library\Think\Think.class.php(120): Think\App::run()
#4 C:\wamp\www\ThinkPHP\ThinkPHP.php(96): Think\Think::start()
#5 C:\wamp\www\test\index.php(7): require_once(‘C:\wamp\www\Thi...‘)
#6 {main}
然後百度得知,開啟了DEBUG偵錯模式後,控制器路徑名要嚴格區分大小寫。頓悟,修改地址為:http://localhost:8080/test/index.php/Index和http://localhost:8080/test/Index.php/index均還是一樣的問題。遂查閱官方手冊是可以修改不區分大小寫:在設定檔中加上一句話:‘URL_CASE_INSENSITIVE‘ => true, // 預設false 表示URL區分大小寫 true則表示不區分大小寫。試了下,還是不行! 想了想,是不是Controller的問題,繼續查閱手冊。得知
自從3.2之後thinkphp預設的控制器不再使用Action,而是使用了更貼近MVC模式的Controller。
如果你原來習慣用了Action,還是可以吧Controller修改成Action的
可以這樣定義:
1 namespace Home\Action;2 use Think\Action;3 class IndexAction extends Action{}
然後,在設定檔config.php中,設定:
1 ‘DEFAULT_C_LAYER‘=>‘Action‘
遂,把Controller修改成Action,還是一樣的問題,我的天!
繼續百度!
發現發現別人的目錄結構和我的好像不一樣!
仔細查看代碼
1 define(‘APP_PATH‘, ‘./home/‘);//定義項目位置
發現3.1產生的home項目目錄下並沒有Home目錄
而3.2產生的home項目目錄卻多了一層Home目錄
因此我們在URL地址上必須加上Home目錄,也就是:http://localhost:8080/test/index.php/Home/Index/index(檔案入口[index.php]/Home[預設]/控制器名[Index]/方法名[index])
瀏覽器粘貼訪問,終於顯示出那誘人可愛的hellow world