我将卫星图像存储在 mysql 数据库中。该表具有纬度、经度属性。我想将它们发送到 Twig 并显示为 map ,我的 php Controller 如下所示。
public function highlightAction()
{
$highlighted=$this->getDoctrine()
->getRepository('AppBundle:satelliteImage')
->findAll();
$images = array();
foreach ($highlighted as $key => $high) {
$images[$key] = base64_encode(stream_get_contents($high->getImage()));
}
return $this->render('satelliteImages/highlighted.html.twig',array(
'highlighted' => $highlighted,
'images' => $images
));
}
我的 Twig 代码是这样的:
<tbody>
{% for key,high in highlighted %}
<tr>
<img alt="Embedded Image" src="data:image/png;base64,{{ images[key] }}" />
</tr>
{% endfor %}
</tbody>
我将图像显示为垂直阵列。任何建议,我可能需要将它们显示为 map 。 Twig 中的二维数组?
最佳答案
你可以这样使用:
<table>
<tbody>
{% for key in 0..2 %}
<tr>
{% for key in 0..3 %}
<td>
<img alt="Embedded Image" src="data:image/png;base64,
{{ images[loop.parent.key*4 + key] }}" />
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
关于php - Twig 中的二维数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41518574/