【发布时间】:2015-03-12 19:42:24
【问题描述】:
我正在尝试在 laravel Blade 视图中使用嵌套对象中的数据。
我正在使用 Laravel 4.2。
这是一个数据样本,“$arContent”:
stdClass Object
(
[h1-title] => stdClass Object
(
[h3-sub-title] => Safe, Affordable Self-Storage
[img] => Array
(
[0] => Caption 1
[1] => Caption 2
[2] => Caption 4
)
)
)
我将它传递给视图,“对象”:
// show the view and pass the page and domain recrods to it
return View::make('objects')
->with('page', $page)
->with('content', $arContent)
->with('domain', $domain);
在这里我试图在视图中检索一个值:
<h2>
{{ $content->h1-title->h3-sub-title }}
</h2>
我从上面得到的错误是:
未定义属性:stdClass::$h1
我也试过了:
<h2>
{{ $content->h1-title->h3-sub-title }}
</h2>
然后我得到以下错误:
语法错误,意外的 '->' (T_OBJECT_OPERATOR),期待 ',' 或 ';'
我认为我想要做的事情很明显:我希望能够访问嵌套对象的值,只要我想访问多少“层”就行。我已经在 Google 上搜索了上面尝试过的不同方法,现在我不知道 Laravel 是否期待不同/不支持这一点,或者我是否在做一些愚蠢的事情。
任何有关如何执行此操作的指导将不胜感激。
【问题讨论】:
-
视图中的
var_dump($content)怎么样 - 这不是解决方案,但可能会有所帮助