简体   繁体   English

您请求的服务“ user_service”不存在

[英]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 : 这是我的代码:

Vendor/BundleNameBundle/Resources/config/services.yml 供应商/捆绑名称捆绑/资源/config/services.yml

services:
    user_service:
         class:  Morescreens\VideomanagerBundle\Service\UserService
         arguments: ['@security.encoder_factory']

app/config/config.yml app / config / config.yml

imports:
    - { resource: "@morescreensVideomanagerBundle/Resources/config/services.yml" }

code for my service 服务代码

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);
   }

}

Inside mine controller: 内部矿山控制器:

 $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: 实际缓存服务定义的文件位于:

  • app/cache/{envName}/ (The cache directory can be configured to be located wherever you want, this is just the default). app / cache / {envName} /(可以将缓存目录配置为位于所需的任何位置,这只是默认设置)。

The files that have the relevent info for container service definitions are: 具有容器服务定义的相关信息的文件是:

  • app{EnvName}DebugProjectContainer.php app {EnvName} DebugProjectContainer.php
  • app{EnvName}DebugProjectContainer.php.meta app {EnvName} DebugProjectContainer.php.meta
  • app{EnvName}DebugProjectContainer.xml app {EnvName} DebugProjectContainer.xml

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您已请求不存在的服务“ phpexcel” - You have requested a non-existent service “phpexcel” 您请求了一个不存在的服务“twig”错误 - You have requested a non-existent service "twig" ERROR 您请求的服务“ knp_paginator”不存在。 - You have requested a non-existent service “knp_paginator”. 您已请求不存在的服务“security.context” - You have requested a non-existent service “security.context” 您请求了一个不存在的服务“模板” - You have requested a non-existent service "templating" Symfony 4.1:你请求了一个不存在的服务“主义” - Symfony 4.1 : You have requested a non-existent service "doctrine" Symfony2 FOSUserBundle-您已请求一个不存在的服务“ security.user_checker” - Symfony2 FOSUserBundle - You have requested a non-existent service “security.user_checker” 您请求了一个不存在的服务“Doctrine”。 您的意思是这个:“教义”吗? - You have requested a non-existent service "Doctrine". Did you mean this: "doctrine"? Symfony2:您请求的服务“ jms_aop.pointcut_container”不存在。 - Symfony2: You have requested a non-existent service “jms_aop.pointcut_container”. 例外 - 您请求了一个不存在的服务“indragunawan.facade.container” - Exception - You have requested a non-existent service "indragunawan.facade.container"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM