Reputation: 31
I have action, but when i send data, i have
Request-URI Too Long. The requested URL's length exceeds the capacity limit for this server
public function addAction(Request $request)
{
$productGallery = new ProductGallery();
$product = new Product();
$productGallery->addProductgalleryToProduct($product);
$form = $this->createForm(new ProductGalleryType(), $productGallery);
if($request->isMethod('POST'))
{
$form->handleRequest($request);
if($form->isValid())
{
$em = $this->getDoctrine()->getManager();
$em->persist($productGallery);
$em->persist($product);
$em->flush();
return $this->redirectToRoute('addAction', array('form' => $form->createView()));
}
}
return array(
'form' => $form->createView()
);
}
How i can fixed it? What i do wrong?
p.s my form collection
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('productgallery_to_product', 'collection', array(
'type' => new ProductType(),
'allow_add' => true,
'by_reference' => false,
'allow_delete' => true,
'prototype' => true
))
;
}
NEW INFO
Method 'POST' In my url
Upvotes: 0
Views: 1102
Reputation: 36211
You're passing a whole form view object in the URL:
$this->redirectToRoute('addAction', array('form' => $form->createView()));
The second argument to redirectToRoute()
is a list of GET parameters to send with the request.
This makes your URL VERY long. It exceeds the web server limit, which in turn refuses to handle the request.
Your call should look more like this:
$this->redirectToRoute('addAction');
Also, the first argument to the redirectToRoute()
method is the route name, not the action method name. Replace it unless your route name is "addAction".
Read more in the Controller chapter of the documentation.
Upvotes: 2