当前位置:网站首页>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]+');
边栏推荐
- Handling of @charset UTF-8 warning problems during vite packaging and construction;
- Idea configuration
- 信息收集的利器,Google骇客语法
- 计算机网络知识总结(面试)
- Summary of push-pull output and open drain output of STM32 and failure of analog IIC driving mlx90615
- Design and process analysis of anti backflow circuit for MOS transistor
- How to effectively promote products
- [system architecture] - what are MDA architecture, ADL and DSSA
- 213. house raiding II
- Electronic training.
猜你喜欢

Multiple interface calls, using promise all、Promise. Race and promise any

返回值为Object型方法调用equals()

Etcd database source code analysis cluster communication initialization

halcon之区域:多种区域(Region)生成(4)

Data analysis slicer, PivotTable and PivotChart (necessary in the workplace)

FIFO code implemented in C language

模板引擎——FreeMarker初体验

FPGA notes -- implementation of FPGA floating point operation

Idea configuration

vite打包构建时 @charset utf-8警告问题处理;
随机推荐
[learn FPGA programming from scratch -44]: vision chapter - integrated circuit helps high-quality development in the digital era -1- main forms of integrated circuit chips
Is it safe to open a fund account? Are there any risks?
多接口调用,使用Promise.all、Promise.race和Promise.any
When you run the demo using the gin framework, there is an error "listen TCP: 8080: bind: an attempt was made to access a socket in a way forbidden"
马斯克 VS 乔布斯,谁是21世纪最伟大的创业家
Final review [machine learning]
mysql错误代码2003的解决办法
2022资料员-通用基础(资料员)考试模拟100题及在线模拟考试
Flex & Bison 开始
C#使用MySql进行操作
What training brings happiness
如何有效地推广产品
[从零开始学习FPGA编程-44]:视野篇 - 集成电路助力数字化时代高质量发展-1-集成电路芯片主要形态
Establish a j-link GDB cross debugging environment for Px4
填鸭数据即时收集解决方案资源
Return value is object type method call equals()
About EF page turning query database
2022安徽省安全员C证考试练习题模拟考试平台操作
单选框互斥且可同时取消选中
SPI protocol