2015-01-14 122 views
0

尝试使用此,Laravel将数组传递给刀片

return View::make('products.tables')->with('json', $json); 

但得到的数组到字符串转换错误。

JSON数组

$json = array (
    "item1" => "no1", 
    "item2" => "no2", 
    "item3" => "no3", 
    ); 
+0

该错误可能发生在别的地方。你可以请发表你的其他代码吗? – lukasgeiter

+0

你能否提供'$ json'变量的结构? – sanis

+0

你如何在你的视图中输出这个? – user3158900

回答

0

这意味着,在你看来,你在呼唤数组项走错了路。

它应该是这样的:

$json->item1 

或者:

@foreach($json as $item) 
    {{ $item }} 
@endforeach 
1

试试这个:

$json = array (
    "item1" => "no1", 
    "item2" => "no2", 
    "item3" => "no3", 
); 

$data = array (
'json' => $json 
); 

return View::make('products.tables')->with($data) 

,然后在您的视图:

@foreach($json as $item) 
    {{ $item }} 
@endforeach 

这应该工作。