I know I'm probably missing something really easy, but I just don't know what, and I'm still pretty new to symfony.
I'd like to have a url like /admin/user/edit/1234
where the controller uses the paramConverter to auto load the user from their ID. But I keep getting an error.
Some mandatory parameters are missing ("id") to generate url for route.
I tried following http://symfony.com/doc/current/best_practices/controllers.html but it's not very detailed in how it all works.
Here's my route
admin_edit_user:
pattern: /users/edit/{id}
defaults: {_controller: MyBundle:AdminUsers:editUser}
requirements:
id: \d+
And here's my controller
<?php
//...
class AdminUsersController extends Controller
{
//...
public function editUserAction(Request $request , User $user)
{
$info = $user->getInfo();
if(is_null($info))
{
$info = new UserInfo();
}
$userInfoForm = $this->createForm(new UserInfoType() , $info , array(
'action' => $this->generateUrl('admin_edit_user')
));
$userInfoForm->handleRequest($request);
if($userInfoForm->isValid())
{
if(is_null($user->getInfo()))
{
$user->setInfo($info);
}
$em = $this->getDoctrine()->getManager();
$em->persist($info);
$em->persist($user);
$em->flush();
$request->getSession()->getFlashBag()->add('notice' , 'User Info succesfully updated.');
}
return $this->render('MyBundle:Admin/Users:edit.html.twig' , array(
'user_info_form' => $userInfoForm->createView(),
'user' => $user
));
}
}