我創建了一個過濾器表單來限制列表中顯示的實體。 它通過POST工作,我需要它來記住狀態,因此,當您使用頁面並稍後返回過濾器時,與您離開時相同。在控制器中填寫表格值
我在會話中存儲過濾器,並在沒有使用POST時加載它們。過濾器效果很好。 但表單不顯示值。我triing結合的形式之前更新請求的值,但是這是不工作,我不知道爲什麼......
$filterForm = $this->createForm(new TourFilter($this->container, $destinations));
$session = $this->getRequest()->getSession();
if ($request->getMethod() == 'POST') {
//This is when I get the request (POST) values to do the filtering
$filterForm->bindRequest($request);
$params = $request->request->get('buv_marketplacebundle_tourfilter');
//in parseFilerParams I do some validation and transforming parameters
$filters = $this->parseFilterParams($params, $base_filters);
//store current params in the session
$session->set('tour_filters', $params);
} else {
//get parameters from the session
$params = $session->get('tour_filters');
if (is_array($params) && count($params) > 0) {
//update the request with the parameters from the session
$request->request->replace(array('buv_marketplacebundle_tourfilter' => $params));
//bind the updated request to the form
$filterForm->bindRequest($request);
$filters = $this->parseFilterParams($params, $base_filters);
} else {
$filters = $base_filters;
}
}
//search for the entities
$entities = $em->getRepository('BuvMarketplaceBundle:Tour')->getFilteredTours($filters);
好,簡單地說,我不得不推動像$ filterForm-> setData($ params)這樣的數據;而不是像你解釋的bindRequest。有用。 Tranks。 – Sergi 2012-02-27 14:20:42