In a controller's action I load a PDO object from the database and send it to the twig template in order to render a data grid:
/**
* @Route("/action1", name="action1")
* @Template()
*/
public function action1Action(Request $request)
{
$mydata = $this->daoClass->getData();
return array(
'mydata' => $mydata
);
}
$myData is loaded using Doctrine which returns me a PDO object with an (small) array of results (PDO Object). I render this like this:
<table>
{% for data in mydata %}
<tr>
<td>{{ data.foo }}</td>
<td>{{ data.bar }}</td>
</tr>
{% endfor %}
</table>
So in the twig template, below the table with the data, I got this form that sends data to the next action:
<form action="{{ path('action2') }}" method="post">
<!-- some javascript populated fields -->
<input type="hidden" id="field1" name="field1">
...
</form>
How can I make it send also the PDO object that rendered the grid (mydata object) ?
I tried to insert it in the session in the first action so I can retrieve it in the next action but got the message: "You cannot serialize or unserialize PDO instances"
Is there any better way to do this ?
I'm not using symfony forms in this module because this is an overly complex screen with lots of validations and calculated fields and it would be much more complicated to use the forms.