我想定义一个带有包含斜杠的参数的路由/
像这样的性格example.com/view/abc/02
where abc/02
是参数。
如何防止 Laravel 将斜杠读取为下一个路由参数的分隔符?因此我得到了404 not found error
now.
将以下包罗万象的路线添加到您的底部routes.php
并记得跑composer dump-autoload
然后。请注意使用“->where”指定参数的可能内容,使您能够使用包含斜杠的参数。
//routes.php
Route::get('view/{slashData?}', 'ExampleController@getData')
->where('slashData', '(.*)');
与在控制器中相比,您只需像平常一样处理数据(就像它不包含斜杠一样)。
//controller
class ExampleController extends BaseController {
public function getData($slashData = null)
{
if($slashData)
{
//do stuff
}
}
}
这应该对你有用。
此外,这里有关于路由参数的详细 Laravel 文档:[docs http://laravel.com/docs/routing#route-parameters ]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)