Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 Symfony 1.4-Don和#x27;t在executeUpdate操作中保存空密码_Php_Symfony1_Passwords_Symfony 1.4 - Fatal编程技术网

Php Symfony 1.4-Don和#x27;t在executeUpdate操作中保存空密码

Php Symfony 1.4-Don和#x27;t在executeUpdate操作中保存空密码,php,symfony1,passwords,symfony-1.4,Php,Symfony1,Passwords,Symfony 1.4,我有一个表单来编辑存储在mysql数据库中的UserProfile。其中包括以下自定义配置: public function configure() { $this->widgetSchema['password']=new sfWidgetFormInputPassword(); $this->validatorSchema['password']->setOption('required', false); // you don't need to sp

我有一个表单来编辑存储在mysql数据库中的UserProfile。其中包括以下自定义配置:

public function configure()
  {
    $this->widgetSchema['password']=new sfWidgetFormInputPassword();
    $this->validatorSchema['password']->setOption('required', false); // you don't need to specify a new password if you are editing a user.
  }
当用户尝试保存时,将调用executeUpdate方法来提交更改。 如果密码为空,则密码字段设置为“”,但我希望它保留旧密码,而不是覆盖旧密码

这样做的最佳方式是什么?我的解决方案是覆盖模型上的setter方法(无论如何我都是为了密码加密而这样做的),并忽略空白值

public function setPassword( $password )
{
  if ($password=='') return false; // if password is blank don't save it.
  return $this->_set('password', UserProfile ::encryptPassword( $password ));
}
这样似乎很好,但有更好的方法吗

如果您想知道我不能将sfDoctrineGuard用于此项目,因为我正在处理一个遗留数据库,并且无法更改架构。

我觉得很好:

public function setPassword($password)
{
  if (!$password) return false;
  return $this->_set('password', UserProfile::encryptPassword($password));
}
我有一些表单需要更新sfGuardUser密码以及与不同型号相关的其他表单字段,最后我得到了如下结果:

$id = // sfGuardUser primary key
$values['password'] = // the form post value returned

if ($values['password']) {
  $user = Doctrine::getTable('sfGuardUser')->find($id);
  $user->setPassword($values['password']);
  $user->save();
}
。。。如果在表单中发布了值,则保存一个值。

我觉得很好:

public function setPassword($password)
{
  if (!$password) return false;
  return $this->_set('password', UserProfile::encryptPassword($password));
}
我有一些表单需要更新sfGuardUser密码以及与不同型号相关的其他表单字段,最后我得到了如下结果:

$id = // sfGuardUser primary key
$values['password'] = // the form post value returned

if ($values['password']) {
  $user = Doctrine::getTable('sfGuardUser')->find($id);
  $user->setPassword($values['password']);
  $user->save();
}

。。。如果在表单中发布了值,则保存一个值。

我在想,可能可以使用后验证器执行某些操作。是的,可能有,但问题是您想在这样的事情上花费多少时间。我同意你目前的工作方案。我在想可能有一些东西可以用后验证器来完成。是的,可能有,但问题是你想花多少时间在这样的事情上。我同意你目前的工作方案。