2017-08-11 53 views
1

這是我的控制器:我想通過ID的數組路線的Symfony

/** 
* @Route("/order", name="finish") 
*/ 
public function createAction(Request $request) 
{ 
    $form = $this->createForm(OrderType::class); 

    // get data using the ids pass to the request... 
    // handle the form and redirect to homepage 

    return $this->render(
     "orders/order_view.html.twig", 
     ['order'=>$form->createView()] 
    ); 

} 

我想一些標識傳遞到請求,以便我能學說得到所需要的數據。 之後,處理表單創建新的訂單,並添加到我已經有了產品感謝ID通過。

我試圖通過使用按鈕單擊ajax的ID:

$.ajax(
     { 
      type: 'POST', 
      url: '/order', 
      data: {'arr':[2,3,4]} // sample ids 
     } 
    ).done(function (data) { 
     console.log(data) 
    }).fail(function() { 
     console.log("some error") 
    }) 

,但它只是返回的HTML。我需要的是呈現在指定的路線(「/訂單」)的形式,所以我可以處理它,並插入到數據庫中的新訂單與產品添加到它

+0

我認爲你可以得到你阿賈克斯使用數據$請求 - >的getContent() –

回答

0

我在這裏回答了這個問題:

Symfony2.8. How to get data from post request

您可以使用POST請求:

$request->request->get('data'); 

對於GET請求:

$request->query->get('data'); 

文件查詢:

$request->files. 
+0

什麼,我需要知道的是如何將數據傳遞到請求 –