Reputation: 11
i thinking break my head.. " The form's view data is expected to be of type scalar, array or an instance of \ArrayAccess, but is an instance of class Puig\IFBBundle\Entity\OrderRow. You can avoid this error by setting the "data_class" option to "Puig\IFBBundle\Entity\OrderRow" or by adding a view transformer that transforms an instance of class Puig\IFBBundle\Entity\OrderRow to scalar, array or an instance of \ArrayAccess. "
i use setData('view data'); to the form in cuestion, but not work and i understand this form to view the result.
My code:
public function listOrdersToExportAction($batchInputFile)
{
$orderRows = $this->getDoctrine()->getRepository('IFBBundle:OrderRow')
->findAllToExport();
$orderRowsAction = new OrderRowsAction();
$orderRowsAction->setOrderRows($orderRows);
$orderRowsAction->setReturnRoute('listOrdersToExport');
$formInvoice = $this->createForm(new OrderRowsActionType(), $orderRowsAction, array('actionType' => 'export'));
return $this->render('IFBBundle:Orders:listOrdersToExport.html.twig', array('orderRows' => $orderRows,
'formInvoice' => $formInvoice->createView(),
'batchInputFile' => $batchInputFile));
}
Upvotes: 1
Views: 3171
Reputation: 1489
Yes as Rpg600 stated, in your form class you need to set the data_class like this:
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver->setDefaults(array(
'data_class' => 'Puig\IFBBundle\Entity\OrderRow',
));
}
Upvotes: 1