symfony3 twig and show session array

zupaaa

I have array in session, but I can't show them. My code: Controller:

  $game = $request->query->get('game');
  $type = $request->query->get('type');
  $odd = $request->query->get('odd');

  $kupon = array(
                 'game' => $game,
                 'type' => $type,
                 'odd' => $odd,
               );

   $this->get('session')->set('kupon', $kupon);

Where 'game' is for example: 'Arsenal - Chelsea', 'type' is number like 1, and odd is float number like '2.2'.

Twig file:

{% if app.session.get('kupon') is not null %}
<table>
{% for kupon in session %}
    <tr>
      <td>{{ kupon.game }}</td>
      <td>{{ kupon.type }}</td>
      <td> </td>
    </tr>
{% endfor %}
</table>

And everything ok, but when I try log in and show data session, I have this error:

Impossible to access an attribute ("game") on a string variable ("PNdjNUeuZ_d5uJlm1VG7zPZhp2Vb4CY3nDf93vAQ574") in baw\kupon.html.twig at line 13.

This variable is from session after log in, I checked dump information about it:

array(3) { 
["_csrf/login"]=> string(43) "PNdjNUeuZ_d5uJlm1VG7zPZhp2Vb4CY3nDf93vAQ574" ["login"]=> string(4) "test" 
["kupon"]=> array(3) { ["game"]=> string(31) "Arsenal Londyn - Chelsea Londyn" ["type"]=> string(1) "1" ["odd"]=> string(3) "2.2" } }

And now I haven't any idea to fix this.

NDM

{% for kupon in session %} will not loop over app.session.get('kupon')

what you want to do is:

{% for kupon in app.session.get('kupon') %}

But looking at you dumped data, app.session.get('kupon') is just a single dataset, so you cant even loop that (with desired results)...

it will be just:

{{ app.session.get('kupon').game }}

extra explanations about your data: you have this in you session:

"kupon" => [
    "game" => ...
    "type" => ...
    ...
]

to be able to loop over these, you need to make a collection of your data types:

"kupon" => [
    [
        "game" => ...
        "type" => ...
        ...
    ],
    [
        "game" => ...
        "type" => ...
        ...
    ],
    ....
]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Symfony session array works fine in controller but not in twig

From Dev

Symfony session cannot be retrieve in twig

From Dev

Symfony3 service not found by twig

From Dev

Symfony3 Session Failed on appengine

From Dev

how does "{% use %}" work in twig using symfony3?

From Dev

javascript function not defines error in Symfony3 twig file

From Dev

Attempted to call an undefined method named "getpreReady" (Twig & Symfony3)

From Dev

how does "{% use %}" work in twig using symfony3?

From Dev

Getting array keys in Twig? (Symfony)

From Dev

symfony twig array key display

From Dev

Getting array keys in Twig? (Symfony)

From Dev

How to read Zend2 session in Symfony3 application

From Dev

How can i access to array key in twig view symfony 3

From Dev

Symfony2: Displaying session variable in a twig throw exception

From Dev

Symfony2 array access in twig error

From Dev

Symfony2: Key no exists in array [twig]

From Dev

Forwarding a php array to twig template (Symfony)

From Dev

Access an array values in twig symfony2

From Dev

Passing array values for loop TWIG+symfony

From Dev

Meta tag from head goes into body on server using twig template symfony3

From Dev

Symfony3 : choice type field filled with array of objects

From Dev

Associative array fields in form builder - Symfony3

From Dev

Howto pass array in ajax call to controller and return it with Symfony3

From Dev

Show JSON data on Twig

From Dev

Show the last 3 clicked links in a php session

From Dev

Symfony3 AJAX request from iframe on the same domain does not save Session attribute

From Dev

Symfony3 AJAX request from iframe on the same domain does not save Session attribute

From Dev

Symfony2 translation yaml array and twig loop

From Dev

Symfony2-Twig- Accessing stdclass object array

Related Related

  1. 1

    Symfony session array works fine in controller but not in twig

  2. 2

    Symfony session cannot be retrieve in twig

  3. 3

    Symfony3 service not found by twig

  4. 4

    Symfony3 Session Failed on appengine

  5. 5

    how does "{% use %}" work in twig using symfony3?

  6. 6

    javascript function not defines error in Symfony3 twig file

  7. 7

    Attempted to call an undefined method named "getpreReady" (Twig & Symfony3)

  8. 8

    how does "{% use %}" work in twig using symfony3?

  9. 9

    Getting array keys in Twig? (Symfony)

  10. 10

    symfony twig array key display

  11. 11

    Getting array keys in Twig? (Symfony)

  12. 12

    How to read Zend2 session in Symfony3 application

  13. 13

    How can i access to array key in twig view symfony 3

  14. 14

    Symfony2: Displaying session variable in a twig throw exception

  15. 15

    Symfony2 array access in twig error

  16. 16

    Symfony2: Key no exists in array [twig]

  17. 17

    Forwarding a php array to twig template (Symfony)

  18. 18

    Access an array values in twig symfony2

  19. 19

    Passing array values for loop TWIG+symfony

  20. 20

    Meta tag from head goes into body on server using twig template symfony3

  21. 21

    Symfony3 : choice type field filled with array of objects

  22. 22

    Associative array fields in form builder - Symfony3

  23. 23

    Howto pass array in ajax call to controller and return it with Symfony3

  24. 24

    Show JSON data on Twig

  25. 25

    Show the last 3 clicked links in a php session

  26. 26

    Symfony3 AJAX request from iframe on the same domain does not save Session attribute

  27. 27

    Symfony3 AJAX request from iframe on the same domain does not save Session attribute

  28. 28

    Symfony2 translation yaml array and twig loop

  29. 29

    Symfony2-Twig- Accessing stdclass object array

HotTag

Archive