首页 > 语言 > PHP > 正文

Laravel框架路由管理简单示例

2024-05-05 00:08:51
字体:
来源:转载
供稿:网友

本文实例讲述了Laravel框架路由管理。分享给大家供大家参考,具体如下:

路由中输出视图

Route::get('/', function () {  return view('welcome');});

get路由请求

Route::get('get',function(){  return 'get路由请求';});

post路由请求

Route::post('post',function(){  return 'post请求';});

多路由请求

Route::match(['get','post'],'match',function(){  return '多路由请求';});

任意路由请求

Route::any('any',function(){  return '任意路由请求';});

路由参数

Route::get('user/{id}',function($id){  return 'user-id-'.$id;});

路由参数默认值

Route::get('user/{name?}',function($name = 'yxh'){  return 'user-name-'.$name;});

路由参数的正则验证

Route::get('user/{id}/{name?}',function($id,$name = 'yxh'){  return 'user-id-'.$id.'-name-'.$name;})->where(['id'=>'[0-9]+','name'=>'[A-Za-z]+']);

路由别名

Route::get('user/member-center',['as'=>'center',function(){  return route('center');}]);

路由群组

Route::group(['prefix'=>'member'],function(){  //路由别名  Route::get('user/member-center',['as'=>'center',function(){    return route('center');  }]);  //任意路由请求  Route::any('any',function(){    return '任意路由请求';  });});

路由中输出视图

Route::get('view',function(){  return view('welcome');});

关联控制器

Route::get('member/info','MemberController@info');Route::get('test','UserController@test');Route::get('query','UserController@query');Route::get('orm','UserController@orm');Route::get('section1',['uses'=>'UserController@section1']);Route::get('url',['as'=>'url','uses'=>'UserController@urlTest']);

希望本文所述对大家基于Laravel框架的PHP程序设计有所帮助。


注:相关教程知识阅读请移步到PHP教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表

图片精选