我在我的项目中使用FOS包。我在管理包中创建了一个新的控制器ChangePasswordController
。这是我的代码。
namespace Pondip\AdminBundle\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\RedirectResponse;
use FOS\UserBundle\Controller\ChangePasswordController as BaseController;
/**
Controller managing the change password *
@author Aman
/
class ChangePasswordController extends BaseController
{
/**
This action is used for change password for admin.
@author Aman
@return render view
@throws AccessDeniedException as exception
@
*/
public function changePasswordAction()
{
$user = $this->container->get('security.context')->getToken()->getUser();
$form = $this->container->get('fos_user.change_password.form');
$formHandler = $this->container->get('fos_user.change_password.form.handler');
$process = $formHandler->process($user);
if ($process) {
$this->setFlash('fos_user_success', 'Password has been changed successfully');
$url = $this->container->get('router')->generate('pondip_admin_changepassword');
return new RedirectResponse($url);
}
return $this->container->get('templating')->renderResponse(
'PondipAdminBundle:ChangePassword:changePassword.html.'.$this->container->getParameter('fos_user.template.engine'),
array('form' => $form->createView())
);
}
}
现在我想为当前密码自定义错误消息。
答案 0 :(得分:1)
你是否重写了FOSUserBundle?见Documentation。如果你不是,那么你应该是,如果你想修改默认行为。
如果是这样,那么您必须在覆盖FOSUserBundle的软件包中复制FOSUserBundle供应商中的翻译文件(和父目录):
Resources / translations / validators.xx.yml其中xx是您的语言环境。
然后更改错误消息。例如,要更改当前密码无效错误,请写:
fos_user:
[...]
current_password:
invalid: Your own error message here
[...]
希望这有帮助!