我正在尝试使用 Twig 在我的页面上呈现一个数组,但我总是收到以下错误代码:
ProfileBundle:Profile 中的模板渲染期间引发了异常(“注意:尝试在 C:\xampp\htdocs\JPP\app\cache\dev\classes.php 行 10098 中获取非对象的属性”) :profile.html.twig 在第 228 行。
当我查看 profile.html.twig 时,我看到以下 for 循环:
`{% for Educations in Education|sortByDate %}
<div id="education{{loop.index0}}">
<tr>
<td class="border">{{ Educations.fromDate|date('d-m-Y') }}</td>
<td> </td>
<td class="border">{{ Educations.toDate|date('d-m-Y') }}</td>
<td> </td>
<td class="border">{{ Educations.company }}</td>
<td> </td>
<td class="border" id="jobsChar{{loop.index0}}">{{ Educations.jobs }}</td>
<td> </td>
<td class="border"><input type="button" title="Show Details" class="showDetails" id="details_show{{loop.index0}}"/><input type="button" title="Edit" class="editJob" id="education_edit{{loop.index0}}" /><form style="display:inline" action="../deleteJob" id="deleteJob"><input type="button" title="Delete Job" class="deleteJob" id="job_delete{{loop.index0}}" /></form></td>
</tr></div>{% endfor %}`
在下面您可以看到应该由 TWIG 的 for 循环处理的数组,但没有成功...
数组(5) { [0]=> 数组(9) { ["id"]=> int(80) ["userId"]=> int(3) ["company"]=> string(24) "Solothurner Spitäler AG" ["jobArea"]=> int(0) ["subJobsArea"]=> int(0) ["jobs"]=> int(2) ["jobLabel"]=> string(8) "Förster" ["fromDate"]=> object(DateTime)#437 (3) { ["date"]=> string(19) "2010-01-01 00:00:00" ["timezone_type"]=> int(3 ) ["timezone"]=> string(13) "Europe/Berlin" } ["toDate"]=> object(DateTime)#436 (3) { ["date"]=> string(19) "2011-02 -09 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } } [1]=> array(9) { ["id "]=> int(87) ["userId"]=> int(3) ["company"]=> string(6) "TOP IT" ["jobArea"]=> int(0) ["subJobsArea"]=> int(0) ["jobs"]= > int(3) ["jobLabel"]=> string(20) "Dipl.Pflegefachfrau" ["fromDate"]=> object(DateTime)#433 (3) { ["date"]=> string(19) " 2008-05-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["toDate"]=> object(DateTime) #432 (3) { ["date"]=> string(19) "2009-05-22 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13 ) "欧洲/柏林" } } [2]=> array(9) { ["id"]=> int(103) ["userId"]=> int(3) ["company"]=> string(10 ) "赫尔萨纳股份公司" ["jobArea"]=> int(0) ["subJobsArea"]=> int(0) ["jobs"]=> int(1) ["jobLabel"]=> string(11) "Holffäller" ["fromDate"] => object(DateTime)#430 (3) { ["date"]=> string(19) "2012-10-01 00:00:00" ["timezone_type"]=> int(3) ["timezone" ]=> string(13) "Europe/Berlin" } ["toDate"]=> object(DateTime)#429 (3) { ["date"]=> string(19) "2013-05-01 00:00 :00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } } [3]=> array(9) { ["id"]=> int (104) ["userId"]=> int(3) ["company"]=> string(8) "ALPIQ AG" ["jobArea"]=> int(0) ["subJobsArea"]=> int(0 ) [“工作”]=>int(2) ["jobLabel"]=> string(8) "Förster" ["fromDate"]=> object(DateTime)#427 (3) { ["date"]=> string(19) "2013-05 -01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } ["toDate"]=> object(DateTime)#426 ( 3) { ["date"]=> string(19) "2013-05-09 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "欧洲/Berlin" } } [4]=> array(9) { ["id"]=> int(130) ["userId"]=> int(3) ["company"]=> string(8) "ALPIQ AG" ["jobArea"]=> int(0) ["subJobsArea"]=> int(0) ["jobs"]=> int(2) ["jobLabel"]=> string(8) "Förster" [ "从日期"]=>object(DateTime)#424 (3) { ["date"]=> string(19) "2013-05-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]= > string(13) "Europe/Berlin" } ["toDate"]=> object(DateTime)#439 (3) { ["date"]=> string(19) "2013-05-09 00:00:00 " ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } } }} } }} } }
请问你能帮我吗?非常感谢。
干杯罗杰