Symfony2请求URI太长


Symfony2 Request-URI Too Long

我有操作,但当我发送数据时,我有

请求URI太长。请求的URL长度超过了此服务器的容量限制

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()
    );
}

我该怎么修?我做错了什么?

p.s我的表格收集

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
        ))
    ;
}

新信息

方法"POST"在我的url 中

http://trololo.com/app_dev.php/add?form%5Bvars%5D%5Bid%5D=games_modelbundle_productgallery&表单%5变量%5D%5名称%5D=games_modelbundle_productgallery&表单%5Vars%5D%5Full_name%5D=games_modelbundle_productgallery&表单%5Vars%5D%5Disabled%5D=0&表单%5变量%5D%5多部分%5D=1&表单%5变量%5D%5Block_prefixes%5D%5B0%5D=表单&表单%5变量%5D%5Block_prefixes%5D%5B1%5D=games_modelbundle_productgallery&表单%5变量%5D%5Block_prefixes%5D%5B2%5D=_games_modelbundle_productgallery&表单%5变量%5D%5Unique_block_prefix%5D=_games_modelbundle_productgallery&表单%5变量%5D%5Bcache_key%5D=_;表单%5Vars%5D%5Read_only%5D=0&表单%5变量%5D%5有效%5D=1&表单%5Vars%5D%5Required%5D=1&形式%5变体%5D%5化合物%5D=1&表单%5变量%5D%5方法%5D=POST&表单%5变量%5D%5操作%5D=&表单%5Vars%5D%5Submitted%5D=1&表单%5子项%5D%5Productgallery_to_product%5D%5Vars%5D%5Bid%5D=games_modelbundle_productgallery_productgallery_to _product&表单%5子项%5D%5productgallery_to_product%5D%5Vars%5D%5Name%5D=productgallery_to_product&表单%5Bchildren%5D%5Bproductgallery_to_product%5D%5B变量%5D%5Bfull_name%5D=游戏_模型捆绑_产品库%5BproductGalllery_to.product%5D&表单%5子项%5D%5productgallery_to_product%5D%5Vars%5D%5Disabled%5D=0&表单%5子项%5D%5productgallery_to_product%5D%5Vars%5D%5Multipart%5D=1&表单%5子项%5D%5productgallery_to_product%5D%5Vars%5D%5Block_prefixes%5D%5%B0%5D=form&表单%5子项%5D%5Productgallery_to_product%5D%5Vars%5D%5Block_prefixes%5D%5%B1%5D=collection&表单%5子项%5D%5产品。。。。。

您正在URL中传递一个完整的表单视图对象:

$this->redirectToRoute('addAction', array('form' => $form->createView()));

redirectToRoute()的第二个参数是要随请求一起发送的GET参数列表。

这会使您的URL非常长。它超过了web服务器的限制,而web服务器又拒绝处理请求。

你的电话应该更像这样:

$this->redirectToRoute('addAction');

此外,redirectToRoute()方法的第一个参数是路由名称,而不是操作方法名称。替换它,除非您的路由名称为"addAction"。

请参阅文档的控制器一章中的更多内容。