我是 Symfony / Twig 的新手,在将对象值传递给我的 Twig 模板时遇到问题。
这是我的一些控制器代码,显示了对象的内容:
$prevArticles = $section->getArticles();
print_r($prevArticles);
die()
显示:
Array
(
[0] => Imagine\NewsletterBundle\Entity\Article Object
(
[id:protected] =>
[title:protected] =>
[headline:protected] =>
[link:protected] =>
[image:protected] =>
[excerpt:protected] =>
[check:protected] =>
[attachment:protected] =>
[field1:protected] =>
[field2:protected] =>
[field3:protected] =>
[magazines:protected] =>
[top_logo_advert:protected] => /uploaded_images/cece0b1859ea2b1af95f1f274620ba77.jpg
[top_logo_alt:protected] => Picture of blomange
[top_logo_link:protected] => www.google.com
)
)
然后我将我的对象传递给我的树枝模板,如下所示:
return $this->render('ImagineNewsletterBundle:Section:'.$builder->getTemplate(), array('prevArticles' => $prevArticles));
然后在我的树枝模板中,我想显示“top_logo_advert”的值,但它不起作用:
{% for article in prevArticles %}
{{ article.top_logo_advert }}
{% endfor %}
我收到错误消息:
Method "top_logo_advert" for object "Imagine\NewsletterBundle\Entity\Article" does not exist in ImagineNewsletterBundle:Section:build_advert.html.twig at line 62