Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 4中路由组前缀中的变量_Php_Variables_Routing_Laravel_Laravel 4 - Fatal编程技术网

Php Laravel 4中路由组前缀中的变量

Php Laravel 4中路由组前缀中的变量,php,variables,routing,laravel,laravel-4,Php,Variables,Routing,Laravel,Laravel 4,鉴于以下路线,它将响应 我想知道的是,我怎样才能让它对 我试过了 Route::group(['prefix' => 'game/{game}'], function($game){ 但由于“缺少{closure}()的参数1”而失败 请注意,除了stats之外,还有四个组,但为了简洁起见,我省略了它们 Route::group(['prefix' => 'game'], function(){ Route::group(['prefix' => 'sta

鉴于以下路线,它将响应



我想知道的是,我怎样才能让它对



我试过了

Route::group(['prefix' => 'game/{game}'], function($game){
但由于“缺少{closure}()的参数1”而失败

请注意,除了stats之外,还有四个组,但为了简洁起见,我省略了它们

Route::group(['prefix' => 'game'], function(){
    Route::group(['prefix' => 'stats'], function(){
        Route::get('/{game}', ['as' => 'game.stats', function ($game) {
            return View::make('competitions.game.allstats');
        }]);
        Route::get('game/{game}', ['as' => 'game.stats.game', function ($game) {
            return View::make('competitions.game.gamestats');
        }]);
        Route::get('reviewer/{game}', ['as' => 'game.stats.reviewer', function ($game) {
            return View::make('competitions.game.reviewstats');
        }]);
    });
});

你能试试这个代码看看它是否是你想要的吗。这里是第二组路由,它只是
{gameId}
,然后是
stats
组,它封装了所有其他路由

Route::group(['prefix' => 'game'], function(){
      Route::group(['prefix' => '{gameId}'], function(){
        Route::group(['prefix' => 'stats'], function(){
          Route::get('/', ['as' => 'game.stats', function ($game) {
              return View::make('competitions.game.allstats');
          }]);
          Route::get('game', ['as' => 'game.stats.game', function ($game) {
             return View::make('competitions.game.gamestats');
          }]);
          Route::get('reviewer', ['as' => 'game.stats.reviewer', function ($game) {
             return View::make('competitions.game.reviewstats');
          }]);
        });
      });
    });
然后在视图中,您可以通过路由名称调用它们,并将
gameId
传递给路由

{{ link_to_route('game.stats','All Stats',123) }}  // game/123/stats/
{{ link_to_route('game.stats.game','Game Stats',123) }} // game/123/stats/game
{{ link_to_route('game.stats.reviewer','Review Stats',123) }} // game/123/stats/reviewer
希望这有助于解决您的问题

编辑

我刚刚检查了它是否也可以与
Route::group(['prefix'=>'game/{game}'
一起使用,正如您所尝试的那样,但是在创建上述路由时,请确保传递
game
参数。如果要传递的变量更多,可以向函数传递数组

{{ link_to_route('game.stats','All Stats',['game' => '123','someOtherVar' => '456']) }}

我注意到您的一些路由参数前缀为“$”,而有些则不是。哎呀,键入,但这没有什么区别,因为参数名称只在您使用路由绑定时才起作用,而我目前不使用路由绑定,所以这只是顺序问题。啊!这是我的问题,我希望在将变量放入路由定义时,您可以ed将变量添加到route closure签名中,您需要对route group closures执行相同的操作。