thinkphp5-路由

2021/10/30 17:15:47

本文主要是介绍thinkphp5-路由,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

路由开关模式

普通模式

'url_route_on'  =>  false,

混合模式

'url_route_on'  =>  true,
'url_route_must'=>  false,

强制模式

'url_route_on'          =>  true,
'url_route_must'        =>  true,

路由定义

route.php

use think\Route;
Route::rule('home','index/index');

path_info方式访问

http://www.tp5.com/index.php/index/index/index/id/5

路由方式访问

http://www.tp5.com/index.php/home/id/5

定义

Route::rule('new/:id','News/update','POST');
Route::get('new/:id','News/read'); // 定义GET请求路由规则
Route::post('new/:id','News/update'); // 定义POST请求路由规则
Route::put('new/:id','News/update'); // 定义PUT请求路由规则
Route::delete('new/:id','News/delete'); // 定义DELETE请求路由规则
Route::any('new/:id','News/read'); // 所有请求都支持的路由规则

资源路由

use think\Route;
Route::resource('home','index/index');

访问

get http://www.tp5.com/index.php/home
get http://www.tp5.com/index.php/home/3
get http://www.tp5.com/index.php/home/3/edit
put http://www.tp5.com/index.php/home/3
delete http://www.tp5.com/index.php/home/3

快捷路由

route.php

Route::controller('home','index/index');

User控制器

namespace app\index\controller;

class Index {
    public function getInfo()
    {
    }

    public function getPhone()
    {
    }

    public function postInfo()
    {
    }

    public function putInfo()
    {
    }

    public function deleteInfo()
    {
    }
}

访问

get http://www.tp5.com/home/info
get http://www.tp5.com/home/phone
post http://www.tp5.com/home/info
put http://www.tp5.com/home/info
delete http://www.tp5.com/home/info

miss路由

Route::miss('public/miss');

生成URL

\think\Url::build('@index/index/read','id=5');
url('@index/index/read','id=5');


这篇关于thinkphp5-路由的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程