1. 程式人生 > >thinkphp路由配置route.php

thinkphp路由配置route.php

路由設定配置

開啟route.php 
引入Route控制器類(use think\Route;)
設定路由--》  Route::rule('路由表示式','路由地址','請求型別','路由引數(陣列)','變數規則(陣列)');

靜態路由例子:

                        use think\Route;
			// 註冊路由到index模組的News控制器的read操作
			Route::rule('new/:id','index/News/read');

			訪問http://serverName/new/5 直接路由到到http://serverName/index/news/read/id/5

                動態帶引數路由:

                Route::rule('course/:id','index/index/course');

		// 批量註冊GET路由
		Route::rule([
		'路由規則1'=>'路由地址和引數',
		'路由規則2'=>['路由地址和引數','匹配引數(陣列)','變數規則(陣列)']
		...
		],'','請求型別','匹配引數(陣列)','變數規則');

		Route::get([
		    'new/:id'  =>  'News/read',
		    'blog/:id' =>  ['Blog/edit',[],['id'=>'\d+']]
		    ...
		]);
		// 效果等同於
		Route::rule([
		    'new/:id'  =>  'News/read',
		    'blog/:id' =>  ['Blog/edit',[],['id'=>'\d+']]
		    ...
		],'','GET');

		//等同於any方式
		return [
		    'new/:id'   => 'News/read',
		    'blog/:id'   => ['Blog/update',['method' => 'post|put'], ['id' => '\d+']],
		];