这是我的功能代码,但是我得到这个错误调用一个成员函数get()on null。所以请帮帮我
public function verificarSenhaDefaultAction() {
$a = "12345678";
$default = $this->get('security.password_encoder')->encodePassword($this->getUser(), $a);
if ($this->getUser()->getPassword() == $default):
return TRUE;
else:
Return FALSE;
endif;
}
答案 0 :(得分:1)
您需要从容器中调用get函数,如下所示:
$this->container->get('security.password_encoder')->encodePassword($this->getUser(), $a);
答案 1 :(得分:0)
对于friendsofsymfony / UserBundle v2.0:
public function verificarSenhaDefaultAction(User $user, $password) {
$encoder = $this->container->get('security.encoder_factory')->getEncoder($user);
return $encoder->isPasswordValid($user->getPassword(), $password, $user->getSalt());
}