[英]You have requested a non-existent service “user_service”
Iam trying to implement service for encoding password but it seems it doesn't work cause I get "You have requested a non-existent service user_service " error. 我正在尝试实施用于编码密码的服务,但似乎无法正常工作,原因是我收到“您已请求不存在的服务user_service”错误。
Here is my code : 这是我的代码:
services:
user_service:
class: Morescreens\VideomanagerBundle\Service\UserService
arguments: ['@security.encoder_factory']
imports:
- { resource: "@morescreensVideomanagerBundle/Resources/config/services.yml" }
class UserService {
/**
* @var EncoderFactoryInterface
*/
private $encoderFactory;
public function __construct(EncoderFactoryInterface $encoderFactory)
{
$this->encoderFactory=$encoderFactory;
}
public function setEncodedPassword(User $user)
{
$encoder=$this->encoderFactory->getEncoder($user);
$password=$encoder->encodePassword($user->getPassword(),$user->getSalt());
$user->setPassword($password);
}
}
$user=new User();
$user->setPassword('password');
$this->get('user_service')->setEncodedPassword($user);
EDIT: 编辑:
I manually deleted cache folder and my service started to work. 我手动删除了缓存文件夹,我的服务开始工作。
Try looking at your src/{VendorName}/{BundleName}Bundle/DependencyInjection/{VendorName}{BundleName}Extension.php 尝试查看您的src / {VendorName} / {BundleName} Bundle / DependencyInjection / {VendorName} {BundleName} Extension.php
This file should load your service definitions like this: 该文件应像这样加载您的服务定义:
<?php
namespace Vendor\{BundleName}Bundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class Vendor{BundleName}Extension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
//Load our YAML resources
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader->load('services.yml');
}
}
This will load the service definition from src/{VendorName}/{BundleName}Bundle/Resources/config/services.yml
into the container. 这将从
src/{VendorName}/{BundleName}Bundle/Resources/config/services.yml
加载服务定义到容器中。 If that still doesn't work try doing php app/console cache:clear
. 如果仍然不能解决问题,请尝试执行
php app/console cache:clear
。 For speed reasons, symfony will basically aggregate all your service (and other configuration files) into a cached file so it doesn't have to read those files every time. 出于速度原因,symfony基本上会将您的所有服务(和其他配置文件)聚合到一个缓存文件中,因此不必每次都读取这些文件。 The files that actually cache the service definitions are located:
实际缓存服务定义的文件位于:
The files that have the relevent info for container service definitions are: 具有容器服务定义的相关信息的文件是:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.