douguizhuang8276 2015-07-17 16:16
浏览 23
已采纳

Symfony2 Request-URI太长

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

  • 写回答

1条回答 默认 最新

  • dthl8036 2015-07-17 16:29
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大