[英]How to override validation message of FOS bundle in symfony2
我在項目中使用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())
);
}
}
現在,我想為當前密碼自定義錯誤消息。
您要覆蓋FOSUserBundle嗎? 請參閱文檔 。 如果不是,那么就應該修改默認行為。
如果是這樣,則必須在覆蓋FOSUserBundle的包中復制在FOSUserBundle供應商中找到的轉換文件(和父目錄):
Resources / translations / validators.xx.yml,其中xx是您的語言環境。
然后更改錯誤消息。 例如,要更改當前密碼無效錯誤,請輸入:
fos_user:
[...]
current_password:
invalid: Your own error message here
[...]
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.