php - Laravel路由调用控制器可变参数问题
阿神
阿神 2017-04-10 18:04:32
0
1
269
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的。

阿神
阿神

闭关修行中......

Antworte allen(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]+|']);

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

Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!