symfony - Symfony2 / Form - Change GET Method generated URL -
i have form method, , action have 3 optional parameters. if submit form, form generate url this: "example.com/keyword=test?category=test1?country=test2"
but route looks "example.com/{keyword}/{category}/{country}"
how can solve issue?
i tried this:
if($form->isvalid()){ return $this->redirect($this->generateurl('route', array('keyword' => $form['keyword']->getdata(), ... ))); }
but can't because render form in ::base.html.twig, , redirection doesn't work ...
searchformaction:
public function searchformaction(request $request) { $form = $this->createform(new searchtype(),null, array('action' => $this->generateurl('web_portal_search'))); $form->handlerequest($request); if($form->isvalid()){ // return $this->redirecttoroute('web_portal_search', // array( // 'keyword' => $form['keyword']->getdata(), // 'category' => $form['category']->getdata(), //// 'country' => $form['country']->getdata() // )); } return $this->render('webportalbundle:default/search:searchform.html.twig', array('searchform' => $form->createview()), $this->get('webportalbundle')->cache($request)); }
searchaction:
public function searchaction($keyword = null, $category = null, $country = null, request $request){ $em = $this->getdoctrine()->getmanager(); $search = $em->getrepository('dbbundle:ads')->search($keyword, $category, $country); return $this->render('webportalbundle:default/search:search.html.twig', array('search' $search)); }
route:
web_portal_search: path: /{keyword}/{category}/{country}/{page} defaults: { _controller: webportalbundle:search:search, keyword: null, category: null, country: null, page: 1 } requirements: _method: page: \d+
::base.html.twig:
... {{ render(controller('webportalbundle:search:searchform')) }} ...
not sure if solve problem, don't need pass request parameter in searchaction. can access request $this->getrequest() anyway.
besides, route has "page" parameter not set in searchaction. think function should written :
public function searchaction($keyword = null, $category = null, $country = null, $page = 1){ // stuff here }
i can't test right let me know if solves problem...
Comments
Post a Comment