1

我想做一些我不知道是否可行的事情。

这是我的 routes.php

Route::get('mockups/user/skills/{skill}', 'MockupsController@user');
Route::get('mockups/user/tours/{tour}', 'MockupsController@user');
Route::get('mockups/user', 'MockupsController@user');

和我的 MockupsController@user 函数

public function user($skill=null,$tour=null){
    if($tour ==null && $skill != null)
        return View::make('demo/mockups/user/public',array('skill'=>$skill));
    if($tour!=null && $skill ==null)
        return View::make('demo/mockups/user/public',array('tour'=>$tour));
    return View::make('demo/mockups/user/public');

}

如果我得到/mockups/user/tours/tour1url,控制器调用demo/mockups/user/public视图而不发送$tour变量。如何使它工作?

编辑

public function user($skill=null,$tour=null){
    echo var_dump($skill);
    echo var_dump($tour);
    die();
    if($tour ==null && $skill != null)
        return View::make('demo/mockups/user/public',array('skill'=>$skill));
    if($tour!=null && $skill ==null)
        return View::make('demo/mockups/user/public',array('tour'=>$tour));
    return View::make('demo/mockups/user/public');

}

显示

string(5) "tour1" NULL 
4

1 回答 1

2

我不明白你为什么把它弄得这么复杂。为什么不只是做

Route::get('mockups/user/skills/{skill}', 'MockupsController@skills');
Route::get('mockups/user/tours/{tour}', 'MockupsController@tours');
Route::get('mockups/user', 'MockupsController@user');

public function skills($skill)
{
    return View::make('demo/mockups/user/public',array('skill'=>$skill));
}

public function tours($tour)
{
    return View::make('demo/mockups/user/public',array('tour'=>$tour));
}

public function user()
{
    return View::make('demo/mockups/user/public');
}
于 2013-08-18T14:57:05.443 回答