码迷,mamicode.com
首页 > 其他好文 > 详细

tp5总结(二)

时间:2017-12-25 18:21:41      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:source   def   配置文件   动态   后台   time   引擎   route   rewrite   

1.简化路由【一方面可以更好的让搜索引擎抓取;另一方面简化路由,利于记忆】

1-1.在【public/】下面创建admin.php 复制index.php 然后绑定前后台模块define(‘BIND_MODEL‘,‘admin‘)和define(‘BIND_MODEL‘,index‘)

eg:http://ww:7070/tp5-2/public/admin和http://ww:7070/tp5-2/public/index

1-2. 隐藏入口文件

开启Apache的配置文件,将LoadModule rewrite_module modules/mod_rewrite.so前面的注释去掉

eg:http://ww:7070/tp5-2/public/index/index

1-3.隐藏public,将index.php入口文件放在根目录下,并且修改相对路径

2.路由

2-1.关闭后台模块的路由:public/admin后面写 【\think\app:route(false)】

2-2.路由模式,修改config.php  [url_route_on和url_route_must]

2-3.修改route.php来修改路由

2-3-1.静态路由 eg:http://ww:7070/tp5-2/ 

use \think\Route;
Route::rule(‘/‘,‘admin/index/index‘); 

2-3-2.动态静态组合

2-3-3.所有路由

<?php
//配置文件注册方式
//return [
//    ‘__pattern__‘ => [
//        ‘name‘ => ‘\w+‘,
//    ],
//    ‘[hello]‘     => [
//        ‘:id‘   => [‘Index/hello‘, [‘method‘ => ‘get‘], [‘id‘ => ‘\d+‘]],
//        ‘:name‘ => [‘Index/hello‘, [‘method‘ => ‘post‘]],
//    ],
//
//];
use think\Route;
Route::rule(‘/‘,‘Index/Index/index1‘);
Route::rule(‘canshu/:id‘,‘Index/Index/canshu‘);//带一个参数
Route::rule(‘time/:year/:month‘,‘Index/Index/time‘);//带两个个参数
Route::rule(‘kexuan/:year/[:month]‘,‘Index/Index/kexuan‘);//带两可选参数
Route::rule(‘:a/:b‘,‘Index/Index/dongtai‘);//全动态路由[不建议用]
Route::rule(‘wanquan$‘,‘Index/Index/wanquan‘);//全动态路由[不建议用]


//设定路由类型
//


Route::rule(‘type‘,‘Index/Index/type‘,‘post|get‘);//即支持get又2支持post

//支持所有

//Route::rule(‘type‘,‘Index/Index/type‘,‘*‘);//支持所有
//Route::any(‘type‘,‘Index/Index/type‘);//支持所有

//put请求
//Route::rule(‘type‘,‘Index/Index/type‘,‘put‘);


//批量注册
//Route::rule([
//    ‘d1‘=>‘admin/index/test1‘,
//    ‘d2‘=>‘admin/index/test2‘
//],‘‘,‘get‘);
Route::get([
    ‘d1‘=>‘admin/index/test1‘,
    ‘d2‘=>‘admin/index/test2‘
]);


//路由规则
Route::rule(‘d3/:id‘,‘admin/index/test3‘,‘get‘,[],[‘id‘=>‘\s+‘]);//参数必须是数字
//Route::rule(‘d3/:id‘,‘admin/index/test3‘,[],[‘id‘=>‘\d{1,3}‘]);//参数必须是数字1-3位

//资源路由 会默认注册七个路由规则  index
Route::resource(‘myblog‘,‘index/myblog‘);

//快捷路由
//Route::controller(‘myblog‘,‘index/myblog‘);

3.路由地址生成 eg:http://ww:7070/tp5-2/public/myblog

tp5总结(二)

标签:source   def   配置文件   动态   后台   time   引擎   route   rewrite   

原文地址:http://www.cnblogs.com/douyaer/p/8087310.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!