sooo基本上我试图用FOS_USER和symphony来改变用户的密码。
代码如下(它与FOS_User交响乐包中的ChangePasswordAction上的代码相同,但响应已更改为使用AJAX
public function changePasswordAction(Request $request) {
// $form = $this->createForm(new ChangePasswordFormType('Bandness\BandeeBundle\Entity\Bandee'), $this->getUser());
$user = $this->getUser();
$dispatcher = $this->container->get('event_dispatcher');
$event = new GetResponseUserEvent($user, $request);
$dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_INITIALIZE, $event);
if (null !== $event->getResponse()) {
return $event->getResponse();
}
$formFactory = $this->container->get('fos_user.change_password.form.factory');
$form = $formFactory->createForm();
$form->setData($user);
if ($request->isMethod('POST')) {
$form->bind($request);
if ($form->isValid()) {
/** @var $userManager \FOS\UserBundle\Model\UserManagerInterface */
$userManager = $this->container->get('fos_user.user_manager');
$event = new FormEvent($form, $request);
$dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_SUCCESS, $event);
$userManager->updateUser($user);
$dispatcher->dispatch(FOSUserEvents::CHANGE_PASSWORD_COMPLETED, new FilterUserResponseEvent($user, $request, new Response()));
return new JsonResponse($this->get('translator')->trans('Bandee.config.changepass.success'),200);
}
else return new JsonResponse($this->getTranslatedErrors($form), 422);
}
事情是这似乎不起作用。当在一个带有php 5.3.6的apache2中它运行得很好,但是在其他机器上它只是不起作用。它通常给出的答复是“不是有效数字”,这没有意义,因为它根本不应该检查一个数字......
我觉得FOS_User和某些版本的PHP存在错误 它不适用于PHP版本5.4.4,也不适用于5.3.10
有什么建议吗?