我试图为Sulu CMF前端用户注册。我想破解密码。但无论什么原因我都不能得到服务。
You have requested a non-existent service "security.encoder_factory".或
You have requested a non-existent service "security.password_encoder"如果我要求
app/console container:debug | grep encode这两种服务都有
$ app/console container:debug | grep encode
263: security.encoder_factory Symfony\Component\Security\Core\Encoder\EncoderFactory
266: security.password_encoder Symfony\Component\Security\Core\Encoder\UserPasswordEncoder 你有什么给我的小费吗?我的控制器知道容器,我的代码如下:
$this->container->get('security.password_encoder')以下是conainer的一些输出:调试
$ app/console container:debug security.password_encoder
[container] Information for service security.password_encoder
Service Id security.password_encoder
Class Symfony\Component\Security\Core\Encoder\UserPasswordEncoder
Tags -
Scope container
Public yes
Synthetic no
Lazy no
Synchronized no
Abstract no
$ app/console container:debug security.encoder_factory
[container] Information for service security.encoder_factory
Service Id security.encoder_factory
Class Symfony\Component\Security\Core\Encoder\EncoderFactory
Tags -
Scope container
Public yes
Synthetic no
Lazy no
Synchronized no
Abstract no我目前安装的symfony版本是v2.6.12
sulu提供的命令使用了这种方法。它在开发和prod两种环境中都能工作。
/**
* Encodes the given password, for the given password, with he given salt and returns the result.
*
* @param $user
* @param $password
* @param $salt
*
* @return mixed
*/
private function encodePassword($user, $password, $salt)
{
/** @var PasswordEncoderInterface $encoder */
$encoder = $this->getContainer()->get('security.encoder_factory')->getEncoder($user);
return $encoder->encodePassword($password, $salt);
}发布于 2016-01-13 12:21:03
正如xabbuh在评论中所指出的,我们在Sulu有两个不同的内核。如果您使用app/webconsole命令,您将使用该网站的内核。
在标准安装中,我们不包括SecurityBundle,因为它增加了一些开销,对于简单的网站来说是不必要的。然而,如果您正在构建一个更复杂的应用程序,您也可能希望保护您的网站。在本例中,您可以简单地将Symfony\Bundle\SecurityBundle\SecurityBundle的一个新实例添加到app/WebsiteKernel中的$bundles数组。之后,也会有您一直要求的服务。
发布于 2016-01-11 15:02:38
Sulu有一个额外的控制台应用程序,名为app/console网络控制台,它使用不同的内核:-)
我搜索的服务在那里不存在。相反,我可以用
$userManager = $this->container->get('sulu_security.user_manager');https://stackoverflow.com/questions/34720312
复制相似问题