前台入口文件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 <?php 2 return array( 3 //'配置項'=>'配置值' 4 'DEFAULT_C_LAYER' => 'Controller', // 默認的控制器層名稱 5 'URL_MODEL' => 1, // URL訪問模式,可選參數0、1、2、3,代表以下四種模式: 6 ); 7 ?>
Controller下的IndexController.class.php文件:
1 <?php 2 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}
自從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