Symfony2 Request-URI太长

时间:2015-07-17 16:16:23

标签: php symfony

我有动作,但是当我发送数据时,我有

  

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

新信息

方法' POST' 在我的网址

  

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 .....

1 个答案:

答案 0 :(得分:2)

您在网址中传递了整个表单视图对象:

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

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

这使您的网址很长。它超出了Web服务器限制,后者又拒绝处理请求。

你的电话应该更像是这样:

$this->redirectToRoute('addAction');

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

,否则请将其替换

在文档的Controller chapter中阅读更多内容。