在树枝错误Symfony2的数组访问 [英] Symfony2 array access in twig error
问题描述
我不知道是怎么回事,但这里是我的predicament:结果
当我想访问树枝嵌套数组我得到这个错误
不可能在一个KprCentarZdravljaBundle整数变量(10977)来访问属性(路径):零件:12行articleDefaultBlock.html.twig
块引用>现在这里是我的枝杈code:
{%如果标志== 0或标志== 1%}
{%设置宽度= 230%}
{%设定高度= 154%}
{%ELSEIF标志== 2%}
{%设置宽度= 60%}
{%设定高度= 60%}
{% 万一 %}{%用于artCats在文章%}
{%用于ARTCAT在artCats%}
{%集img_url = globalimagepath〜的文章/〜artCat.path%}
{%集CID = artCat.cid%}
{%集catname = artCat.name%}
{%集aPath =路径(article_details',{'ID':artCat.id,'catname':catname | pathauto,标题:artCat.title | pathauto})}%
<立GT;
<物品>
{%如果loop.first%}
{%如果标志== 0或标志== 1%}
< H3>< A HREF ={{路径(category_details',{'ID':CID,'名':catname | pathauto})}}> {{catname |传情(28)}}&LT ; / A>&下; / H3>
{% 万一 %}
{%如果标志= 3%!}< A HREF ={{aPath}}>< IMG SRC ={{形象(的http://〜app.request.getHttpHost()〜资产( img_url))zoomCrop(宽度,高度)的.jpeg}}ALT ={{artCat.title}}方式>&下; / A> {%ENDIF%}
&所述; H1>&下; A HREF ={{aPath}}> {{artCat.title |挑逗(79)}}&下; / A>&下; / H1>
{%其他%}
< H2>< A HREF ={{路径(article_details',{'ID':artCat.id,'catname':artCat.name | pathauto,标题:artCat.title | pathauto})}} > {{artCat.title |挑逗(37)}}&下; / A>&下; / H2>
{% 万一 %}
< /条>
< /李>
{%ENDFOR%}
{%ENDFOR%}这是我在树枝变量文章调试:
阵列(4){
[Zdravljeopćenito] =&放大器; GT;
阵列(11){
[0] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(11659)
[标题] =&放大器; GT;
串(36)Brinete励澳zdravlju svojihočiju?
[路径] =&放大器; GT;
串(18)1330007101_516.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[1] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(14663)
[标题] =&放大器; GT;
串(29)Otkrijteuzročnikealergija!
[路径] =&放大器; GT;
串(18)1380196476_342.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[2] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(14664)
[标题] =&放大器; GT;
串(24)Uzroci bolovaùkukovima
[路径] =&放大器; GT;
串(18)1380195386_853.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[3] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(14665)
[标题] =&放大器; GT;
串(13)Napadi panike
[路径] =&放大器; GT;
串(18)1380195261_180.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[4] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(11170)
[标题] =&放大器; GT;
串(28)CAJ ODružmarina考lijek
[路径] =&放大器; GT;
串(18)1380116708_577.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[5] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10970)
[标题] =&放大器; GT;
串(35)Začinite我produžitesvojživot!
[路径] =&放大器; GT;
串(18)1380031350_101.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[6] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(11171)
[标题] =&放大器; GT;
串(32)Meditacijom做punineživljenja
[路径] =&放大器; GT;
串(18)1380103969_112.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[7] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10973)
[标题] =&放大器; GT;
串(20)Zaštovolimo CIMET?
[路径] =&放大器; GT;
串(18)1379579290_899.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[8] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10977)
[标题] =&放大器; GT;
串(32)Simptomi hormonalneneravnoteže
[路径] =&放大器; GT;
串(18)1379507943_927.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[9] =安培; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10978)
[标题] =&放大器; GT;
串(46)CAJ ODđumbira - ukusni napitak曲liječi
[路径] =&放大器; GT;
串(18)1379419241_320.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
[10] =安培; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10979)
[标题] =&放大器; GT;
串(24)Zaštovolimoružmarin?
[路径] =&放大器; GT;
串(18)1379335723_831.jpg
[CID] =&放大器; GT;
INT(266)
[名称] =&放大器; GT;
串(18)Zdravljeopćenito
}
}
[Izgled我ljepota] =&放大器; GT;
阵列(3){
[0] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(14662)
[标题] =&放大器; GT;
串(20)的Joga ZAmršavljenje
[路径] =&放大器; GT;
串(18)1380198181_298.jpg
[CID] =&放大器; GT;
INT(268)
[名称] =&放大器; GT;
串(16)Izgled我ljepota
}
[1] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10971)
[标题] =&放大器; GT;
串(32)Najbolja prehrana ZA瓦苏kožu
[路径] =&放大器; GT;
串(18)1379939148_517.jpg
[CID] =&放大器; GT;
INT(268)
[名称] =&放大器; GT;
串(16)Izgled我ljepota
}
[2] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10974)
[标题] =&放大器; GT;
串(30)Najčešćiuzročnicirosacee
[路径] =&放大器; GT;
串(18)1379579025_722.jpg
[CID] =&放大器; GT;
INT(268)
[名称] =&放大器; GT;
串(16)Izgled我ljepota
}
}
[Seks我veze] =&放大器; GT;
阵列(1){
[0] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10975)
[标题] =&放大器; GT;
串(19)10 mitovaÒorgazmu
[路径] =&放大器; GT;
串(18)1379578683_758.jpg
[CID] =&放大器; GT;
INT(270)
[名称] =&放大器; GT;
串(11)Seks我veze
}
}
[体育我rekreacija] =&放大器; GT;
阵列(1){
[0] =&放大器; GT;
阵列(5){
[ID] =&放大器; GT;
INT(10976)
[标题] =&放大器; GT;
串(41)STO本身događa小号tijelom卡达vježbate?
[路径] =&放大器; GT;
串(18)1379577938_298.jpg
[CID] =&放大器; GT;
INT(271)
[名称] =&放大器; GT;
串(18),体育我rekreacija
}
}
}有关某种原因,我不能访问任何变量的嵌套数组中...
解决方案
不可能在一个整数变量访问属性(路径)
(10977)的
KprCentarZdravljaBundle零部件:articleDefaultBlock.html.twig 12行
块引用>你得到的错误只与阵列(一个ID为10977)在第8元素?不要迭代实现这一元素之前的工作?
I don't know what is going on but here is my predicament:
When I want to access nested arrays in twig I get this errorImpossible to access an attribute ("path") on a integer variable ("10977") in KprCentarZdravljaBundle:Parts:articleDefaultBlock.html.twig at line 12
Now here is my twig code:
{% if flag == 0 or flag == 1 %} {% set width = 230 %} {% set height = 154 %} {% elseif flag == 2 %} {% set width = 60 %} {% set height = 60 %} {% endif %} {% for artCats in articles %} {% for artCat in artCats %} {% set img_url = globalimagepath ~ "articles/" ~ artCat.path %} {% set cid = artCat.cid %} {% set catname = artCat.name %} {% set aPath = path('article_details', {'id': artCat.id, 'catname': catname|pathauto, 'title': artCat.title|pathauto}) %} <li> <article> {% if loop.first %} {% if flag == 0 or flag == 1 %} <h3><a href="{{ path('category_details', {'id': cid, 'name': catname|pathauto}) }}">{{ catname|teaser(28) }}</a></h3> {% endif %} {% if flag != 3 %}<a href="{{ aPath }}"><img src="{{ image('http://'~ app.request.getHttpHost() ~ asset(img_url)).zoomCrop(width,height).jpeg }}" alt="{{ artCat.title }}"></a>{% endif %} <h1><a href="{{ aPath }}">{{ artCat.title|teaser(79) }}</a></h1> {% else %} <h2><a href="{{ path('article_details', {'id': artCat.id, 'catname': artCat.name|pathauto, 'title': artCat.title|pathauto}) }}">{{ artCat.title|teaser(37) }}</a></h2> {% endif %} </article> </li> {% endfor %} {% endfor %}
And here is my debug of the variable articles in twig:
array(4) { ["Zdravlje općenito"]=> array(11) { [0]=> array(5) { ["id"]=> int(11659) ["title"]=> string(36) "Brinete li o zdravlju svojih očiju?" ["path"]=> string(18) "1330007101_516.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [1]=> array(5) { ["id"]=> int(14663) ["title"]=> string(29) "Otkrijte uzročnike alergija!" ["path"]=> string(18) "1380196476_342.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [2]=> array(5) { ["id"]=> int(14664) ["title"]=> string(24) "Uzroci bolova u kukovima" ["path"]=> string(18) "1380195386_853.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [3]=> array(5) { ["id"]=> int(14665) ["title"]=> string(13) "Napadi panike" ["path"]=> string(18) "1380195261_180.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [4]=> array(5) { ["id"]=> int(11170) ["title"]=> string(28) "Čaj od ružmarina kao lijek" ["path"]=> string(18) "1380116708_577.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [5]=> array(5) { ["id"]=> int(10970) ["title"]=> string(35) "Začinite i produžite svoj život!" ["path"]=> string(18) "1380031350_101.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [6]=> array(5) { ["id"]=> int(11171) ["title"]=> string(32) "Meditacijom do punine življenja" ["path"]=> string(18) "1380103969_112.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [7]=> array(5) { ["id"]=> int(10973) ["title"]=> string(20) "Zašto volimo cimet?" ["path"]=> string(18) "1379579290_899.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [8]=> array(5) { ["id"]=> int(10977) ["title"]=> string(32) "Simptomi hormonalne neravnoteže" ["path"]=> string(18) "1379507943_927.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [9]=> array(5) { ["id"]=> int(10978) ["title"]=> string(46) "Čaj od đumbira - ukusni napitak koji liječi" ["path"]=> string(18) "1379419241_320.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } [10]=> array(5) { ["id"]=> int(10979) ["title"]=> string(24) "Zašto volimo ružmarin?" ["path"]=> string(18) "1379335723_831.jpg" ["cid"]=> int(266) ["name"]=> string(18) "Zdravlje općenito" } } ["Izgled i ljepota"]=> array(3) { [0]=> array(5) { ["id"]=> int(14662) ["title"]=> string(20) "Joga za mršavljenje" ["path"]=> string(18) "1380198181_298.jpg" ["cid"]=> int(268) ["name"]=> string(16) "Izgled i ljepota" } [1]=> array(5) { ["id"]=> int(10971) ["title"]=> string(32) "Najbolja prehrana za vašu kožu" ["path"]=> string(18) "1379939148_517.jpg" ["cid"]=> int(268) ["name"]=> string(16) "Izgled i ljepota" } [2]=> array(5) { ["id"]=> int(10974) ["title"]=> string(30) "Najčešći uzročnici rosacee" ["path"]=> string(18) "1379579025_722.jpg" ["cid"]=> int(268) ["name"]=> string(16) "Izgled i ljepota" } } ["Seks i veze"]=> array(1) { [0]=> array(5) { ["id"]=> int(10975) ["title"]=> string(19) "10 mitova o orgazmu" ["path"]=> string(18) "1379578683_758.jpg" ["cid"]=> int(270) ["name"]=> string(11) "Seks i veze" } } ["Sport i rekreacija"]=> array(1) { [0]=> array(5) { ["id"]=> int(10976) ["title"]=> string(41) "Što se događa s tijelom kada vježbate?" ["path"]=> string(18) "1379577938_298.jpg" ["cid"]=> int(271) ["name"]=> string(18) "Sport i rekreacija" } } }
For some reason I can't access any of the variables in the nested array...
解决方案Impossible to access an attribute ("path") on a integer variable ("10977") in KprCentarZdravljaBundle:Parts:articleDefaultBlock.html.twig at line 12
Do you get the error only with the 8th element in the array (the one with id 10977)? Do the iterations work before reaching that element ?
这篇关于在树枝错误Symfony2的数组访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!