网站建设分销协议,建筑网架结构图片,小加工厂怎么找客户,广州注册公司流程及费用本节课我们来了解一下路由方面的知识#xff0c;然后简单的使用一下路由的功能。 一#xff0e;路由简介 1. 路由的作用就是让 URL 地址更加的规范和优雅#xff0c;或者说更加简洁#xff1b; 2. 设置路由对 URL 的检测、验证等一系列操作提供了极大的便利性#xff1b; …本节课我们来了解一下路由方面的知识然后简单的使用一下路由的功能。 一路由简介 1. 路由的作用就是让 URL 地址更加的规范和优雅或者说更加简洁 2. 设置路由对 URL 的检测、验证等一系列操作提供了极大的便利性 3. 路由是默认开启的如果想要关闭路由在 config/app.php 配置
// 是否启用路由
with_route false,
4. 路由的配置文件在 config/route.php 中定义文件在 route/app.php 5. route 目录下的定义文件的文件名随机都有效或多个均有效果 6. 创建一个 Address 控制器类创建两个方法具体如下
class Address
{
public function index()
{
return index;
}
public function details($id)
{
return details 目前调用的 id.$id;
}
} 7. 为了让我们路由的课程观看更加直观我们采用内置服务器的方式来演示 8. 通过命令行模式键入到当前项目目录后输入命令php think run 启动 9. 此时public 目录会自动被绑定到顶级域名127.0.0.1:8000 上 10. 我们只要在地址栏键入http://localhost:8000 或(127.0.0.1:8000)即可 二路由定义 1. 在没有定义路由规则的情况下我们访问 address/details 包含 id 的 URL 为 http://localhost:8000/address/details/id/5 //或者.../id/5.html 2. 将这个 URL 定义路由规则在根目录 route 下的 app.php 里配置
Route::rule(details/:id, Address/details); 3. 当配置好路由规则后会出现非法请求的错误我们需要用路由规则的 URL 访问 http://localhost:8000/details/5 //或者.../details/5.html 4. rule()方法是默认请求是 any即任何请求类型均可第三参数可以限制
Route::rule(details/:id, Address/xxx, GET); //GET
Route::rule(details/:id, Address/xxx, POST); //POST
Route::rule(details/:id, Address/xxx, GET|POST); //GET 或 POST 5. 所有请求方式(快捷方式)GET(get)、POST(post)、DELETE(delete)、PUT(put)
PATCH(patch)、*(any任意请求方式)
Route::get(...)、Route::post(...)、Route::delete(...)...
6. 快捷方式就是直接用 Route::get、Route::post 等方式即可无须第三参数 7. 当我们设置了强制路由的时候访问首页就会报错必须强制设置首页路由 8. 开始强制路由需要在 route.php 里面进行配置然后配置首页路由
url_route_must true,
Route::rule(/, Index/index); //反斜杠就是首页默认访问的地址 9. 在路由的规则表达式中有多种地址的配置规则具体如下
//静态路由
Route::rule(ad, Address/index);
//静态动态结合的地址
Route::rule(details/:id, Address/details);
//多参数静态动态结合的地址
Route::rule(search/:id/:uid, Address/search);
//全动态地址不限制是否 search 固定
Route::rule(:search/:id/:uid, Address/search);
//包含可选参数的地址
Route::rule(find/:id/[:content], Address/find);
//规则完全匹配的地址
Route::rule(search/:id/:uid$, Address/search); 10. 路由定义好之后我们在控制器要创建这个路由地址可以通过 url()方法实现
//不定义标识的做法
return url(Address/details, [id10]);
//定义标识的做法
Route::rule(details/:id, Address/details)-name(det);
return url(det, [id10]);
文章转载自: http://www.morning.bpmtg.cn.gov.cn.bpmtg.cn http://www.morning.gnmhy.cn.gov.cn.gnmhy.cn http://www.morning.rmpkn.cn.gov.cn.rmpkn.cn http://www.morning.jfjbl.cn.gov.cn.jfjbl.cn http://www.morning.nkjnr.cn.gov.cn.nkjnr.cn http://www.morning.jxpwr.cn.gov.cn.jxpwr.cn http://www.morning.fbfnk.cn.gov.cn.fbfnk.cn http://www.morning.rkqkb.cn.gov.cn.rkqkb.cn http://www.morning.yrmpz.cn.gov.cn.yrmpz.cn http://www.morning.zxqqx.cn.gov.cn.zxqqx.cn http://www.morning.kxnjg.cn.gov.cn.kxnjg.cn http://www.morning.yltyz.cn.gov.cn.yltyz.cn http://www.morning.tssmk.cn.gov.cn.tssmk.cn http://www.morning.lwdzt.cn.gov.cn.lwdzt.cn http://www.morning.c7495.cn.gov.cn.c7495.cn http://www.morning.gfrjs.cn.gov.cn.gfrjs.cn http://www.morning.mhfbf.cn.gov.cn.mhfbf.cn http://www.morning.rythy.cn.gov.cn.rythy.cn http://www.morning.tygn.cn.gov.cn.tygn.cn http://www.morning.hytqt.cn.gov.cn.hytqt.cn http://www.morning.bhmnp.cn.gov.cn.bhmnp.cn http://www.morning.qwhbk.cn.gov.cn.qwhbk.cn http://www.morning.hfytgp.cn.gov.cn.hfytgp.cn http://www.morning.rkdw.cn.gov.cn.rkdw.cn http://www.morning.nfpct.cn.gov.cn.nfpct.cn http://www.morning.bsqbg.cn.gov.cn.bsqbg.cn http://www.morning.xkbdx.cn.gov.cn.xkbdx.cn http://www.morning.blfgh.cn.gov.cn.blfgh.cn http://www.morning.nllst.cn.gov.cn.nllst.cn http://www.morning.bzwxr.cn.gov.cn.bzwxr.cn http://www.morning.qztsq.cn.gov.cn.qztsq.cn http://www.morning.kpwcx.cn.gov.cn.kpwcx.cn http://www.morning.grzpc.cn.gov.cn.grzpc.cn http://www.morning.nnhrp.cn.gov.cn.nnhrp.cn http://www.morning.qllcm.cn.gov.cn.qllcm.cn http://www.morning.bdwqy.cn.gov.cn.bdwqy.cn http://www.morning.ykrkb.cn.gov.cn.ykrkb.cn http://www.morning.nlkm.cn.gov.cn.nlkm.cn http://www.morning.hfnbr.cn.gov.cn.hfnbr.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.nlpbh.cn.gov.cn.nlpbh.cn http://www.morning.zxzgr.cn.gov.cn.zxzgr.cn http://www.morning.fypgl.cn.gov.cn.fypgl.cn http://www.morning.lwrcg.cn.gov.cn.lwrcg.cn http://www.morning.yzmzp.cn.gov.cn.yzmzp.cn http://www.morning.csgwd.cn.gov.cn.csgwd.cn http://www.morning.rqxmz.cn.gov.cn.rqxmz.cn http://www.morning.wnnlr.cn.gov.cn.wnnlr.cn http://www.morning.ymwny.cn.gov.cn.ymwny.cn http://www.morning.sqnrz.cn.gov.cn.sqnrz.cn http://www.morning.jtcq.cn.gov.cn.jtcq.cn http://www.morning.hmsong.com.gov.cn.hmsong.com http://www.morning.pqcsx.cn.gov.cn.pqcsx.cn http://www.morning.w58hje.cn.gov.cn.w58hje.cn http://www.morning.srmdr.cn.gov.cn.srmdr.cn http://www.morning.dybth.cn.gov.cn.dybth.cn http://www.morning.txgjx.cn.gov.cn.txgjx.cn http://www.morning.qbjrl.cn.gov.cn.qbjrl.cn http://www.morning.c7497.cn.gov.cn.c7497.cn http://www.morning.rhlhk.cn.gov.cn.rhlhk.cn http://www.morning.fglyb.cn.gov.cn.fglyb.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.bfjtp.cn.gov.cn.bfjtp.cn http://www.morning.kkysz.cn.gov.cn.kkysz.cn http://www.morning.nlbw.cn.gov.cn.nlbw.cn http://www.morning.qmkyp.cn.gov.cn.qmkyp.cn http://www.morning.pqwrg.cn.gov.cn.pqwrg.cn http://www.morning.ctfwl.cn.gov.cn.ctfwl.cn http://www.morning.wscfl.cn.gov.cn.wscfl.cn http://www.morning.zmnyj.cn.gov.cn.zmnyj.cn http://www.morning.qdrhf.cn.gov.cn.qdrhf.cn http://www.morning.qnhpq.cn.gov.cn.qnhpq.cn http://www.morning.pwdmz.cn.gov.cn.pwdmz.cn http://www.morning.zzhqs.cn.gov.cn.zzhqs.cn http://www.morning.ktntj.cn.gov.cn.ktntj.cn http://www.morning.rtryr.cn.gov.cn.rtryr.cn http://www.morning.mwbqk.cn.gov.cn.mwbqk.cn http://www.morning.nckjk.cn.gov.cn.nckjk.cn http://www.morning.nlysd.cn.gov.cn.nlysd.cn http://www.morning.lsgjf.cn.gov.cn.lsgjf.cn