当前位置:网站首页>Laravel基础课 路由和MVC——路由
Laravel基础课 路由和MVC——路由
2022-06-25 23:34:00 【DJ Fry】
路由
场景:将用户的请求转发给相应的程序进行处理;
作用:建立URL和程序(处理函数)之间的映射;
类型:get,post,put,pathc,delete
路径:app/Http/route.php
基础路由
Route::get('get', function () {
return 'routes test get';
});
Route::post('post', function () {
return 'routes test post';
});
多请求路由
Route::match(['get', 'post'],'match', function () {
return 'test match multy1';
});
路由参数
Route::get('user/{id}', function ($id) {
return 'get id is '.$id;
})->where('id','[0-9]+');
Route::get('user/{name?}', function ($name = null) {
return 'get name is '.$name;
});
Route::get('user/{name?}', function ($name = '设置默认值') {
return 'get name is '.$name;
});
Route::get('user/{name?}', function ($name = '设置默认值') {
return 'get name is '.$name;
})->where('name','[A-Za-z]+');
/*设置条件*/
Route::get('user/{name}/{id?}', function ($name = 'dename' , $id = 'deid') {
return 'get name is '.$name.' and id is '.$id;
})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);/*多个参数 where里用数组形式*/
路由别名
Route::get('/member/member-center', ['as'=>'center',function () {
return 'member-center i am '.route('center');
}]);
路由群组
route::group(['prefix'=>'member'],function (){
Route::get('user', function () {
return 'user in member';
});
Route::get('test ', function () {
return 'test in member';
});
http:localhost:8880/member/test
});
路由中输出视图
Route::get('view', function () {
return view('welcomeroute');
});
Route::get('view2', function () {
return view('layouts');
});
两种调用controller
Route::get('member/info', '[email protected]');
Route::get('member/info1', ['uses'=>'[email protected]']);
别名
Route::get('member/info2', ['uses'=>'[email protected]','as'=>'memberinfo']);
参数绑定
Route::get('member/{id}', ['uses'=>'[email protected]'])
->where('id','[0-9]+');
边栏推荐
- Web information collection, naked runners on the Internet
- halcon之区域:多种区域(Region)生成(4)
- MOS管防倒灌电路设计及其过程分析
- C disk cleaning strategy of win10 system
- Web學習之TypeScript
- 2022年育婴员(五级)考试试题及答案
- Download and install flume
- QT cmake pure C code calls the system console to input scanf and Chinese output garbled code
- 信息收集的利器,Google骇客语法
- 新库上线 | CnOpenDataA股上市公司IPO申报发行文本数据
猜你喜欢
Error 65:access violation at 0x58024400: no 'read' permission
Vscode shortcut
Digital circuit - adder
新库上线 | CnOpenDataA股上市公司IPO申报发行文本数据
Summary of push-pull output and open drain output of STM32 and failure of analog IIC driving mlx90615
《产品思维30讲》精华及感想
Redis的安装及启动
RT-Thread 项目工程搭建和配置--(Env Kconfig)
New library launched | cnopendata China new house information data
Black box test - decision table method of test cases
随机推荐
卡通shader
Data analysis slicer, PivotTable and PivotChart (necessary in the workplace)
填鸭数据即时收集解决方案资源
Digital circuit - adder
Handling of @charset UTF-8 warning problems during vite packaging and construction;
jarvisoj_ level2_ x64
数组中的第K个最大元素
Freertos+stm32l+esp8266+mqtt protocol transmits temperature and humidity data to Tencent cloud IOT platform
C disk cleaning strategy of win10 system
Cartoon shader
I2C protocol
[从零开始学习FPGA编程-44]:视野篇 - 集成电路助力数字化时代高质量发展-1-集成电路芯片主要形态
sqlserver 区分字符串中字母大小写
Anaconda beginner's notes
Black box test - decision table method of test cases
剑指 Offer II 096. 字符串交织
What training brings happiness
Android cache usage tool class
数字电路——加法器
From query database performance optimization to redis cache - talk about cache penetration, avalanche and breakdown