在我的 Symfony 3 项目中,我制作了以下控制器:
/**
* @Route("/person_in_need/{id}",name="person_in_need_view")
*/
public function viewPersonInNeed(Request $request,$id)
{
}
我想从另一个控制器重定向它,例如:
/**
* @Route("/person_in_need/add",name="add_person_in_need")
*/
public function addPersonInNeed(Request $request)
{
$form=$this->createForm(PersonInNeedType::class,new PersonInNeed());
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
/**
* @var PersonInNeedBusinessLogicModel $dataInsert
*/
$dataInsert=$this->get('app.person_in_need_business_model');
$name=$form->get(PersonInNeedConstats::PERSON_IN_NEED_NAME)->getData();
$surname=$form->get(PersonInNeedConstats::PERSON_IN_NEED_SURNAME)->getData();
$reason=$form->get(PersonInNeedConstats::PERSON_IN_NEED_REASON)->getData();
$dataInsert->registerPersonInNeed($name,$surname,$reason);
//Pass id there
// return $this->redirectToRoute('person_in_need_view');
}
return $this->render('social_worker/add_person_in_need.html.twig',array(
'form'=>$form->createView()
));
}
我将如何id
使用路由名称重定向和传递参数?