2014-02-20 83 views
0

我在我的項目中使用了FOS捆綁包。我在管理包中創建了一個新的控制器ChangePasswordController。這是我的代碼。如何覆蓋symfony2中FOS捆綁包的驗證消息

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()) 
); 
} 

} 

現在我想爲當前密碼自定義錯誤消息。

回答

1

你是否壓倒FOSUserBundle?見Documentation。如果你不是,那麼你應該是,如果你想修改默認行爲。

如果是的話,你就必須複製,在你的包被重寫FOSUserBundle,翻譯文件(父目錄)在FOSUserBundle廠商發現:

資源/譯/ validators.xx.yml哪裏xx是您的語言環境。

然後更改錯誤消息。例如,要更改當前密碼無效錯誤,請寫:

fos_user: 
    [...] 
    current_password: 
     invalid: Your own error message here 
    [...] 

希望這有助於您!