4 基础:路由参数
没有搞明白的
1 绑定模型
2 动态参数
知识梳理
1 路由参数可以混合使用,有任何一条不通过,当前理由就不会生效
2 批量设置路由参数 option()方法 数组传入
伪静态配置
配置文件里默认是 'url_html_suffix' => 'html',
//1 false 禁止使用伪静态
//2 '' 允许任意后缀的伪静态访问
//3 html 只允许设置的后缀伪静态访问
//4 html|shtml 允许多个伪静态后缀
1)后缀检测
//1 允许的后缀 Route::rule('news/:id','news/hello')->ext('html|shtml'); http://www.blog.com/admin/news/5.html //可以访问 http://www.blog.com/admin/news/5.shtml //可以访问 http://www.blog.com/admin/news/5.php //这样就访问不了 //2 禁止的后缀 ->denyExt('jpg|png|gif');
2)HTTPS 访问检测
->https();
3)域名检测
//1 完整域名检测
Route::get('路由表达式','路由地址')->domain('完整域名');
//2 子域名检测
Route::get('nes/id','News/index')->domain('news');
4)请求类型检测
->ajax();( 常用 ) ->pjax(); ->json();
5)请求变量检测
// 检查type变量 Route::post('new/:id', 'News/save')->filter('type', 1); // 检查多个请求变量 Route::post('new/:id', 'News/save') ->filter([ 'type' => 1,'status'=> 1 ]);
6)隐式追加参数
Route::rule('news','news/hello')->append(['city'=>'北京']);//必须用数组传参 不支持字符串 append传递的参数不在url中体现 是额外传递的 控制器获取参数 直接传入 public function hello($citty){ return $city; }
7)路由绑定模型
Route::get('hello/:id', 'index/hello') ->model('\app\index\model\User'); 后期再研究
8)请求缓存
Route::get('new/:name$', 'News/read')->cache(3600);
9)动态参数
后期再研究
10)数组配置多个参数
//1 定义路由 Route::rule('news','news/hello')->option([ 'ext' => 'html', 'append' => ['city'=>'上海'], ]); //2 控制器定义 public function hello($city){ return $city; } //2 访问路由
http://www.blog.com/admin/news.html //返回:上海
1)参数列表


浙公网安备 33010602011771号