【发布时间】:2013-12-13 15:28:11
【问题描述】:
我正在为我的应用程序使用 Sonata 管理包,一切正常,在我的应用程序中,我有用户和管理员,管理员可以在我尝试更新用户时添加/编辑/删除用户密码数据有问题从用户表中覆盖。我已经覆盖了管理控制器的preUpdate 方法,我得到了$object,它有一个用户实体管理器的实例,所以如果用户离开以更新密码并保存数据,密码就会丢失。
public function preUpdate($object)
{
$Password = $object->getUserPassword();
if (!empty($Password)) { /* i check here if user has enter password then update it goes well*/
$salt = md5(time());
$encoderservice = $this->getConfigurationPool()->getContainer()->get('security.encoder_factory');
$User = new User();
$encoder = $encoderservice->getEncoder($User);
$encoded_pass = $encoder->encodePassword($Password, $salt);
$object->setUserSalt($salt)->setUserPassword($encoded_pass);
} else { /* here i try to set the old password if user not enters the new password but fails */
$object->setUserPassword($object->getUserPassword());
}
}
当我尝试设置$object->setUserPassword($object->getUserPassword()); 时,它会变为 null 并将密码更新为 null 它没有获得编辑数据我试图再次获取存储库(如下)以获取密码但运气不一样
$DM = $this->getConfigurationPool()->getContainer()->get('Doctrine')->getManager()->getRepository("...")->find(id here);
有没有办法在实体管理器中访问当前实体的原始数据
【问题讨论】:
标签: php symfony doctrine-orm sonata-admin sonata