我正在使用 Illuminate 访问我的数据库
<body>
<?php
$edges = Edge::all();
foreach ($edges as $key => $value) {
print $value;
}
?>
</body>
浏览器返回:
{"childID":"A","parentID":"C","updated_at":null,"created_at":null}{"childID":"B","parentID":"E","updated_at":null,"created_at":null}{"childID":"C","parentID":"D","updated_at":null,"created_at":null}{"childID":"C","parentID":"F","updated_at":null,"created_at":null}{"childID":"Y","parentID":"Z","updated_at":"2014-08-07 10:26:54","created_at":"2014-08-07 10:26:54"}
至少对我来说奇怪或出乎意料的是我的结果以 JSON 格式返回。如果您能对此有所了解,即为什么会这样,或者原因是......我将不胜感激。
如果我将结果转储到浏览器中:
<?php
print '<pre>';print_r($edges);
?>
产生:
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
[0] => Edge Object
(
[connection:protected] =>
[table:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[original:protected] => Array
(
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[fillable:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[touches:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
[1] => Edge Object
(...)
...
)
就前端结果而言 - 我真的只对以下内容感兴趣:
[childID] => A
[parentID] => C
[updated_at] =>
[created_at] =>
物体的一部分;仅不在 JSON 中;纯文本。