"路由位址和參數"(使用路由前提是URL支援phthinfo和開啟路由"/> "路由位址和參數"(使用路由前提是URL支援phthinfo和開啟路由">

首頁  >  文章  >  php框架  >  laravel和thinkphp路由區別

laravel和thinkphp路由區別

(*-*)浩
(*-*)浩原創
2019-10-30 10:32:283454瀏覽

laravel和thinkphp路由區別

laravel路由有以下這些功能:

#基本路由路由重定向視圖路由路由參數必填參數選用參數正規表示式約束命名路由路由組中間件命名空間子網域路由路由前綴路由命名前綴路由模型綁定隱式綁定明確綁定頻率限製表單方法偽造存取目前路由 (建議學習:laravel開發

所有Laravel 路由都定義在位於routes 目錄下的路由檔案中,這些檔案會透過框架自動載入。

routes/web.php 檔案定義了 web 介面的路由,這些路由被分配了 web 中間件組,從而可以提供 session 和 csrf 防護等功能。 routes/api.php 中的路由是無狀態的,被指派了 api 中介軟體群組。

對大多數應用程式而言,都是從 routes/web.php 檔案開始定義路由。

直接現學現用TP5的路由功能。基本上已經實現了網站的偽靜態存取。

// 域名绑定到index网站模块
Route::domain('mydomain.com, function () {
    //首页
    Route::rule('/','index/Index/index')->ext('html');
    //产品列表
    Route::rule('/products-list//','index/Index/lists')
        ->pattern(['c' => '\w+', 'catid' => '\d+'])
        ->ext('html')
        ->name('product_lists');
    //产品详情
    Route::rule('/item//','index/Index/details')
        ->pattern(['i' => '\w+', 'id' => '\d+'])
        ->ext('html')
        ->name('product_details');
    //产品搜索
    Route::rule('/search/-','index/Index/search','POST|GET')
        ->pattern(['q' => '\w+', 'catid' => '\d+'])
        ->ext('html')
        ->name('site_search');
    //网站页面
    Route::rule('/','index/Index/pages')
        ->pattern(['p' => '\w+'])
        ->ext('html')
        ->name('site_pages'); 
    //不存在
    Route::miss('index/Index/index');
});

路由作用

1.根據實作定義的路由規則,檢驗URL請求,確定執行或拒絕;

2.路由規則可自訂,隱藏了原始URL位址,使存取位址,使存取更安全,位址更優雅。

laravel與thinkphp路由差異:

Laravel必須先定義,再使用,路由檔案為routes.php;TP在設定檔中開啟路由後,路由格式是:"路由表達式" => "路由位址和參數"(使用路由的前提是URL支援phthinfo並且開啟路由),路由可以使URL更符合SEO。

以上是laravel和thinkphp路由區別的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn