How can i access this multi URL in laravel 4?

你说的曾经没有我的故事 提交于 2019-12-13 22:15:34

问题


How can i access this multi URL in laravel 4.2.

http://localhost/new/public/library/course/1/First%20Video

My code is

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);
});

回答1:


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);

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);


来源:https://stackoverflow.com/questions/31840122/how-can-i-access-this-multi-url-in-laravel-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!