thinkphp無法載入模組解決辦法

來源:互聯網
上載者:User

標籤: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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.