Arrays 将Laravel路径中的阵列传递到刀片模板
我试图将一组值从Laravel中的Arrays 将Laravel路径中的阵列传递到刀片模板,arrays,laravel,blade,Arrays,Laravel,Blade,我试图将一组值从Laravel中的routes.php传递到刀片模板中的@foreach循环。以下是我的路线: Route::get('/', function() { $theColors = array("red","green","blue","yellow"); return View::make('hello', array('theLocation' => 'NYC', 'theWeather'=> 'stormy', 'theColors')); })
routes.php
传递到刀片模板中的@foreach
循环。以下是我的路线:
Route::get('/', function()
{
$theColors = array("red","green","blue","yellow");
return View::make('hello', array('theLocation' => 'NYC', 'theWeather'=> 'stormy', 'theColors'));
});
和我的刀片模板代码:
@foreach ($theColors as $color)
<p>The color is {{$color}}.</p>
@endforeach
@foreach($color作为$color)
颜色为{{$color}}
@endforeach
我的日志显示模板中的变量-
$theColors
-未定义。我做错了什么?您没有正确地将$theColors
传递给视图
改变
return View::make('hello', array('theLocation' => 'NYC', 'theWeather'=> 'stormy', 'theColors'));
到
完美-我知道我错过了一些基本的东西。谢谢
return View::make('hello', array('theLocation' => 'NYC', 'theWeather'=> 'stormy', 'theColors' => $theColors));