Laravel - 尝试从刀片模板中的数组中回显值。使用 php echo() 但不是刀片语法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21338801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel - trying to echo a value from an array in a blade template. Works using php echo() but not blade syntax
提问by Inigo
I have an array that looks like:
我有一个看起来像的数组:
$myArray = array(
'firstRow' => array(
0 => array(
'id' => 1
'title' => 'First Cat.'
),
1 => array(
'id' => 2
'title' => 'Second Cat.'
)
),
'SecondRow' => array(
0 => array(
'id' => 3
'title' => 'Third Cat.'
),
1 => array(
'id' => 4
'title' => 'Fourth Cat.'
)
)
);
This is being passed to my blade template. I can echo out values using raw php like:
这将传递给我的刀片模板。我可以使用原始 php 回显值,例如:
<?php echo $myArray['firstRow'][0]['title'] ?>
Which works as expected. However, when I try to do what I thought was exactly the same thing using blade's syntax:
这按预期工作。但是,当我尝试使用刀片的语法做我认为完全相同的事情时:
{{ $myArray['firstRow'][0]['title'] }}
I get the error:
我收到错误:
Trying to get property of non-object
试图获取非对象的属性
?
?
采纳答案by Inigo
OK.. I just solved this. Stupid. Sorry and thanks to the other commenters here.
好的..我刚刚解决了这个问题。愚蠢的。抱歉并感谢这里的其他评论者。
The problem was that I had come code underneath this line which was commented out using HTML comments, ie <-- --> But it also contained blade syntax which of course is PHP and so is still firing. I would normally have noticed but due to my GUI not highlighting blade syntax it went unnoticed.
问题是我在这行下面的代码中使用了 HTML 注释,即 <-- --> 但它也包含当然是 PHP 的刀片语法,因此仍在触发。我通常会注意到,但由于我的 GUI 没有突出显示刀片语法,因此没有引起注意。
回答by Antonio Carlos Ribeiro
I'm afraid you are suspecting of the wrong line of code, because:
恐怕您怀疑代码行错误,因为:
Trying to get property of non-object
Is to something being used not as an array, but as an object:
不是用作数组,而是用作对象的东西:
{{ $myArray->firstRow->get(0)->title }}
So, your error is not exactly in this line.
所以,你的错误并不完全在这一行。
But can be sure by getting the generated view source code in app/storage/views
.
但是可以通过在app/storage/views
.