任何人都可以帮助我,我在这里绝望! 我正在研究一个symfony 3项目,我有不同的操作来将数据保存到数据库或更新它,但它们都没有工作。代码很好我猜它是路由的问题。这是将元素添加到数据库
的操作public function newAction(Request $request)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
...
}
return $this->render('SocialProMeetingBundle::ajoutMeeting.html.twig', array('users'=>$users));
}
这是更新操作
public function editAction(Request $request, Meeting $meeting)
{
...
if($request->isMethod('POST')) {
...
return $this->redirectToRoute('meeting_edit', array(
'id' => $meeting->getId()
));
}
return $this->render('meeting/edit.html.twig', array(
'meeting' => $meeting,
));
}
这是我的路由文件
meeting_index:
path: /
defaults: { _controller: "SocialProMeetingBundle:Meeting:index" }
methods: GET
meeting_show:
path: /show
defaults: { _controller: "SocialProMeetingBundle:Meeting:show" }
methods: [GET, POST]
meeting_new:
path: /new
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]
meeting_edit:
path: /{id}/edit
defaults: { _controller: "SocialProMeetingBundle:Meeting:edit" }
methods: [GET, POST]
meeting_delete:
path: /{id}/delete
defaults: { _controller: "SocialProMeetingBundle:Meeting:delete" }
methods: DELETE
答案 0 :(得分:1)
您的函数newAction
中存在一个问题:传递meeting
参数并且路由无法处理它。这段代码:
return $this->redirectToRoute('meeting_new', array(
'meeting' => $meeting
));
您的路线需要像这样处理参数:
meeting_new:
path: /new/{meeting}
defaults: { _controller: "SocialProMeetingBundle:Meeting:new" }
methods: [GET, POST]