如何在laravel 4中访问此多URL? [英] How can i access this multi URL in laravel 4?
本文介绍了如何在laravel 4中访问此多URL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在laravel 4.2中访问此多URL.
How can i access this multi URL in laravel 4.2.
http://localhost/new/public/library/course/1/前%20Video
我的代码是
Route::get('library/course/{id}', function($id){
return View::make('course')->with('id',$id);
});
Route::get('library/course/{id}/{video}', function($id, $video){
$array = array('id' => '$id', 'video' => '$video');
return View::make('course')->withvideos($array);
});
推荐答案
您正在正确访问该URL,它应该到达第二条路由.
You are accessing the URL correctly, and it should reach your second route.
但是您的路线存在错误:
But you have a bug in your route:
// Your code
$array = array('id' => '$id', 'video' => '$video');
您不应在变量周围加上单引号-应当是:
You shouldn't put single quotes around your variables -- it should be:
$array = array('id' => $id, 'video' => $video);
单引号强制PHP不能解析这两个变量,因此它们只是文字字符串,而不是您想要的.
The single quotes force PHP not to resolve the two variables, so they are simply literal strings -- not what you want here.
此外,要将参数传递给视图,您应该调整代码以使用:
Also, to pass the parameters to the view, you should adjust your code to use:
return view('course', $array);
这篇关于如何在laravel 4中访问此多URL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文