Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过symfony 3.4中的redirectToRoute将id从一个控制器传递到另一个控制器?_Symfony - Fatal编程技术网

如何通过symfony 3.4中的redirectToRoute将id从一个控制器传递到另一个控制器?

如何通过symfony 3.4中的redirectToRoute将id从一个控制器传递到另一个控制器?,symfony,Symfony,我想通过以下方式将父亲id从Symfony中的父亲控制器传输到母亲控制器: return $this->redirectToRoute('mother_new', array('id' => $father->getId())); 我将在母亲控制器中使用父亲id作为: public function motherAction(Request $request,Father $father) 但这将返回以下错误: '无法猜测如何从参数“父”的请求信息中获取条令实例。父亲和母

我想通过以下方式将父亲id从Symfony中的父亲控制器传输到母亲控制器:

return $this->redirectToRoute('mother_new', array('id' => $father->getId())); 
我将在母亲控制器中使用父亲id作为:

public function motherAction(Request $request,Father $father)
但这将返回以下错误:

'无法猜测如何从参数“父”的请求信息中获取条令实例。父亲和母亲的关系是单一的


请问有谁能帮我吗?

你能换掉这个试试吗


公共函数motherAction(父$Father,请求$Request)

它没有变化。仍然显示“无法猜测如何从参数“父亲”的请求信息中获取条令实例”。@simbo您可以演示您的路由定义吗?我使用的是yml not注释,并且母亲的路由为母亲。\u新:路径:/register childby mother默认值:{控制器:“GRBHBundle:母亲:母亲”}方法:[GET,POST]现在,我犯了错误。我没有在我的路由路径上传递{id}/@simbo事实上,为此我想看看路由定义:)你能不能也为那个动作添加
route
定义?母亲的路径是:mother\u new:path:/register childby默认值:{u controller:“GRBHBundle:mother:mother”}方法:[GET,POST]父的路径是:父\新:路径:/daa'ima galmeesssu默认值:{u controller:“GRBHBundle:Father:Father”}方法:[GET,post两个注意事项:您没有
id
(表示)路由定义中的父对象。这是您想要的吗?我的意思是,生成该url将附加
id
作为查询字符串参数。如果这是必需的,并且您想要将该参数作为查询字符串参数,我建议。您也可以是的,就是它。我有错误!