Ubuntu使用——15(thinkphp路由報錯Non-static method think\Route::get() should not be called statically)


在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;”的問題,注釋掉果真成功了。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM