在route.php中添加代碼:
use think\Route;
Route::get('/',function (){
return 'hello world';
});
在瀏覽器中輸入http://localhost/tp5-git/public/index.php,報錯:
[8192] ErrorException in route.php line 13
Non-static method think\Route::get() should not be called statically
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
use think\Route;
Route::get('/',function (){
return 'hello world';
});
Route::get('think', function () {
return 'hello,ThinkPHP5!';
});
Route::get('hello/:name', 'index/hello');
return [
解決方法是:注釋掉“use think\Route;”即可。
成功界面:

思考:觀察route.php中自帶的代碼,發現他們都沒有“use think\Route;”,在網上搜索沒有找到明確的解決方案,但仔細思考,可能就是“use think\Route;”的問題,注釋掉果真成功了。
