我是 Symfony2 的新手,我正在尝试使用内部的服务覆盖控制器
这是寄存器控制器
class RegistrationController extends BaseController
{
public function registerAction(Request $request)
{
/** @var $formFactory \FOS\UserBundle\Form\Factory\FactoryInterface */
$formFactory = $this->container->get('fos_user.registration.form.factory');
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->container->get('fos_user.user_manager');
/** @var $dispatcher \Symfony\Component\EventDispatcher\EventDispatcherInterface */
$dispatcher = $this->container->get('event_dispatcher');
$user = $userManager->createUser();
$user->setEnabled(true);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_INITIALIZE, new UserEvent($user, $request));
$form = $formFactory->createForm();
$form->setData($user);
if ('POST' === $request->getMethod()) {
$form->bind($request);
if ($form->isValid()) {
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_SUCCESS, $event);
$userManager->updateUser($user);
if (null === $response = $event->getResponse()) {
$url = $this->container->get('router')->generate('easy_app_user_profile');
$response = new RedirectResponse($url);
}
$dispatcher->dispatch(FOSUserEvents::REGISTRATION_COMPLETED, new FilterUserResponseEvent($user, $request, $response));
//create UserInfo
$doctrine = $this->container->get('doctrine');
$userInfo = new UserInformation();
$userInfo->setUser($user);
//save the userInfo
$em = $doctrine->getManager();
$em->persist($userInfo);
$em->flush();
//add user first login
$loginManager = $this->get('user_login_manager');
$loginManager->saveUser($request, $user);
return $response;
}
}
return $this->container->get('templating')->renderResponse('FOSUserBundle:Registration:register.html.'.$this->getEngine(), array(
'form' => $form->createView(),
));
}
}
接近尾声我正在使用
$loginManager = $this->get('user_login_manager');
$loginManager->saveUser($request, $user);
但我不能使用 get 因为这不是扩展控制器。所以我不知道如何在这个控制器中访问我的服务
谢谢