ThinkPHP 5.1域名路由实践

浏览:3458 发布日期:2018/05/19 分类:ThinkPHP5专区 关键字: thinkphp5路由 域名路由
原来用TP3.2.3的网站,现在全面升级成TP5.1, 直接现学现用TP5的路由功能。基本已经实现了网站的伪静态访问。

TP5.1的路由功能真的是非常强大,同时学习难度也不小。

同一个入口,实现前台与后台分开访问。

路由配置如下:// 域名绑定到index网站模块
Route::domain('mydomain.com, function () {
    //首页
    Route::rule('/','index/Index/index')->ext('html');
    //产品列表
    Route::rule('/products-list/<catid>/<c?>','index/Index/lists')
        ->pattern(['c' => '\w+', 'catid' => '\d+'])
        ->ext('html')
        ->name('product_lists');
    //产品详情
    Route::rule('/item/<id>/<i?>','index/Index/details')
        ->pattern(['i' => '\w+', 'id' => '\d+'])
        ->ext('html')
        ->name('product_details');
    //产品搜索
    Route::rule('/search/<q?>-<catid?>','index/Index/search','POST|GET')
        ->pattern(['q' => '\w+', 'catid' => '\d+'])
        ->ext('html')
        ->name('site_search');
    //网站页面
    Route::rule('/<p?>','index/Index/pages')
        ->pattern(['p' => '\w+'])
        ->ext('html')
        ->name('site_pages'); 
    //不存在
    Route::miss('index/Index/index');
});
最佳答案
评论( 相关
后面还有条评论,点击查看>>