如何在laravel中设置动态页面URL

时间:2015-08-05 08:45:56

标签: laravel laravel-4

我正在使用Laravel 4.2创建一个网站(在线课程参加应用)。

我在/ library设置了路线以列出我的所有课程。

我现在要做的就是当用户点击网址上的任何课程名称时重定向用户,例如/ library / course / coursename但是我无法这样做。

我发现有点像

<?php

class LibraryController extends BaseController {


    public function getIndex()
    {
        return View::make('library');
    }



    public function getCourse($list){
        return $list;
    }

}

1 个答案:

答案 0 :(得分:2)

#In your routes.php:

    Route::post('library/course/{coursenames?}', array('as' =>    'post.coursename', 'uses' => 'LibraryController@postCoursename'));

#In your LibraryController.php:
    private function postCoursename($coursenames=null){
     $coursenames = array('bscs'=>'CS','bsit'=>,'IT');
     return View::make('library',compact('coursenames'));
     }
#In your blade views:
    @foreach($coursenames as $coursename)
    {{link_to_route('post.coursename',$coursename->bscs, [$coursename->bscs])}}
    {{link_to_route('post.coursename',$coursename->bsit, [$coursename->bsit])}}
    @endforeach

then check your view there was a links called:

[CS][1]
[IT][2]
then try to click the link and see the address url if it's changing.

  [1]: http://localhost/library/course/cs
  [2]: http://localhost/library/course/it