4

I have satellite images stored in a mysql database. The table has attributes latitude,longitude. I want to send them to the twig and display as a map, my php controller looks like this.

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

    ));

}

My twig code is this:

    <tbody>
    {% for key,high in highlighted %}
        <tr>
            <img alt="Embedded Image" src="data:image/png;base64,{{ images[key] }}" />

        </tr>
    {% endfor %}
    </tbody>

I am displaying the images as a vertical array. Any suggestions, I might need to display them as a map. A two dimensional array in twig?

2
  • Hi and welcome. What is your problem ? What does mean "display as a map" ? Commented Jan 7, 2017 at 6:39
  • 1
    I have 12 satellite images in the database. When they are arranged as a 3x4 array they would form a map.(since they are parts of one big area). Right now I'm only able to display them as a vertical list.....I do not have much knowledge on php or twig Commented Jan 7, 2017 at 6:59

1 Answer 1

3

You can use something like this:

<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>

Read the Twig for documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

Hi, Thanks.It worked perfectly. However say I don't know the size of the array and its like 100 images. I only know the difference between each latitude and longitude. (say 0.00875) Any idea on how to display a similar map using the two attributes latitude and longitude?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.