Symfony2 Request-URI Too Long

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

http://trololo.com/app_dev.php/add?form%5Bvars%5D%5Bid%5D=games_modelbundle_productgallery&form%5Bvars%5D%5Bname%5D=games_modelbundle_productgallery&form%5Bvars%5D%5Bfull_name%5D=games_modelbundle_productgallery&form%5Bvars%5D%5Bdisabled%5D=0&form%5Bvars%5D%5Bmultipart%5D=1&form%5Bvars%5D%5Bblock_prefixes%5D%5B0%5D=form&form%5Bvars%5D%5Bblock_prefixes%5D%5B1%5D=games_modelbundle_productgallery&form%5Bvars%5D%5Bblock_prefixes%5D%5B2%5D=_games_modelbundle_productgallery&form%5Bvars%5D%5Bunique_block_prefix%5D=_games_modelbundle_productgallery&form%5Bvars%5D%5Bcache_key%5D=_games_modelbundle_productgallery_games_modelbundle_productgallery&form%5Bvars%5D%5Bread_only%5D=0&form%5Bvars%5D%5Bvalid%5D=1&form%5Bvars%5D%5Brequired%5D=1&form%5Bvars%5D%5Bcompound%5D=1&form%5Bvars%5D%5Bmethod%5D=POST&form%5Bvars%5D%5Baction%5D=&form%5Bvars%5D%5Bsubmitted%5D=1&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bid%5D=games_modelbundle_productgallery_productgallery_to_product&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bname%5D=productgallery_to_product&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bfull_name%5D=games_modelbundle_productgallery%5Bproductgallery_to_product%5D&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bdisabled%5D=0&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bmultipart%5D=1&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bblock_prefixes%5D%5B0%5D=form&form%5Bchildren%5D%5Bproductgallery_to_product%5D%5Bvars%5D%5Bblock_prefixes%5D%5B1%5D=collection&form%5Bchildren%5D%5Bprodu.....

Upvotes: 0

Views: 1102

Answers (1)

Jakub Zalas
Jakub Zalas

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

Related Questions