php - Laravel路由调用控制器可变参数问题
阿神
阿神 2017-04-10 18:04:32
0
1
277
Route::get('/{model}/{name}{restrict}-{classid}{page}.html', function ($model = '', $name = '', $restrict = '', $classid = 0, $page = 1) {
    // function
})->where(['model'=>'android|ipad|iphone|mac|tv', 'name'=>'[\w]+', 'restrict'=>'-hot|-best|', 'classid'=>'[0-9]+', 'page'=>'-[0-9]+|']);

路由规则如上,因为restrict参数可以为空,所以当url中不存在restrict时,参数中就不会传递$restrict了,结果导致第三个参数传递的是classid,有什么办法解决这个问题吗?
另外这个路由规则在老版本的laravel中是支持的,即使没有匹配到restrict,参数列表也是传递$restrict的。

阿神
阿神

闭关修行中......

모든 응답(1)
PHPzhong
Route::get('/{model}/{name}{restrict?}-{classid?}{page?}.html', function ($model = '', $name = '', $restrict = '', $classid = 0, $page = 1) {
    // function
})->where(['model'=>'android|ipad|iphone|mac|tv', 'name'=>'[\w]+', 'restrict'=>'-hot|-best|', 'classid'=>'[0-9]+', 'page'=>'-[0-9]+|']);

应该一个 ? 就能解决问题吧

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!