Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/297.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何覆盖symfony2中FOS捆绑包的验证消息_Php_Mysql_Symfony 2.1 - Fatal编程技术网

Php 如何覆盖symfony2中FOS捆绑包的验证消息

Php 如何覆盖symfony2中FOS捆绑包的验证消息,php,mysql,symfony-2.1,Php,Mysql,Symfony 2.1,我在我的项目中使用FOS包。我在我的管理包中创建了一个新的控制器ChangePasswordController。这是我的密码 namespace Pondip\AdminBundle\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Red

我在我的项目中使用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
    [...]
希望这有帮助