Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/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
Laravel路由-如何将变量传递给子例程?_Laravel_Laravel 4_Laravel Routing - Fatal编程技术网

Laravel路由-如何将变量传递给子例程?

Laravel路由-如何将变量传递给子例程?,laravel,laravel-4,laravel-routing,Laravel,Laravel 4,Laravel Routing,我正在使用组逻辑来过滤我网站的管理部分。我有这样一个路由: Route::group(array('before' => 'auth'), function() { $datas['user']['email'] = Auth::user()->email; Route::get('admin/dashboard', function() { return View::make('admin/dashboard')->with(array('

我正在使用组逻辑来过滤我网站的管理部分。我有这样一个路由:

Route::group(array('before' => 'auth'), function() {

    $datas['user']['email'] = Auth::user()->email;

    Route::get('admin/dashboard', function() {
        return View::make('admin/dashboard')->with(array('datas' => $datas));
    });
    //other routes...
});

如何使$DATA可用于我的组中包含的所有路由?

您可以共享变量:

View::share('datas', $datas);
return View::make('admin/dashboard');

如您所述,您希望在每个路由中包含$DATA,您可以使用use关键字:

您可以了解use关键字。

看看这个答案。
Route::group(array('before' => 'auth'), function()
{
    $datas['user']['email'] = Auth::user()->email;

    Route::get('admin/dashboard', function() use ($datas)
    {
        return View::make('admin/dashboard')->with(array('datas' => $datas));
    });
});