Laravel Group动态地将变量传递给控制器

时间:2014-06-11 18:32:57

标签: laravel laravel-4 laravel-routing

我正在做一个语言路由组,但一切都是动态的,这是我的路由器生成器:

foreach(Language::All() as $language)
{
    //prefix
    Route::group(array('prefix' => $language->prefijo), function()  use ($language)
    {
        //in this i need to know the prefix
        // or passing the $language variable to controller
        Route::controller('/{menuSel}', 'RaizController');
    });
}

我需要在控制器中使用变量$ prefix或$ language,这是我的控制器:

class RaizController extends BaseController {

    public function getIndex($menuSel)
    {
        //here i have the $menuSel variable, bul also need the $language or the prefix
        return $menuSel;
    }
}

我正在使用laravel 4.2。

1 个答案:

答案 0 :(得分:1)

您可以检索请求URI段:

$language = Request::segment(1); // 1 is the index of segment