【问题标题】:Service "fos_elastica.finder.app.user" not found找不到服务“fos_elastica.finder.app.user”
【发布时间】:2019-01-12 17:16:25
【问题描述】:

Symfony 找不到 fos_elastica 的服务

Service "fos_elastica.finder.app.user" not found: even though it exists in the app's container, the container inside "App\Controller\DevController" is a smaller service locator that only knows about the "doctrine", "form.factory", "http_kernel", "parameter_bag", "request_stack", "router", "security.authorization_checker", "security.csrf.token_manager", "security.token_storage", "session" and "twig" services. Unless you need extra laziness, try using dependency injection instead. Otherwise, you need to declare it using "DevController::getSubscribedServices()".

我的配置

# Read the documentation: https://github.com/FriendsOfSymfony/FOSElasticaBundle/blob/master/Resources/doc/setup.md
fos_elastica:
    clients:
        default: { host: localhost, port: 9200 }
#    indexes:
#        app: ~
    indexes:
        app:
            client: default
            types:
                user:
                    properties:
                        username: ~
#                    mappings:
#                        email: ~
                    persistence:
                        # the driver can be orm, mongodb, phpcr or propel
                        # listener and finder are not supported by
                        # propel and should be removed
                        driver: orm
                        model: App\Entity\User
                        provider: ~
                        listener: ~
                        finder: ~

我的控制器:

    /**
     * @Route("/search")
     */
    public function searchElastic(){
        /** var array of App\Entity\User */
        $finder = $this->container->get('fos_elastica.finder.app.user');
        return new response('N/A');
    }

command php bin/console fos:elastica:populate 没有抛出任何错误,并且在 phpstorm 中它没有突出显示(这意味着 phpstorm 找到了它)

请帮帮我。

【问题讨论】:

    标签: symfony elastica


    【解决方案1】:

    你应该像这样使用依赖注入:

    在控制器类use FOS\ElasticaBundle\Manager\RepositoryManagerInterface;中添加use语句,那么你的动作应该是这样的:

    /**
     * @Route("/search")
     */
    public function searchElastic(RepositoryManagerInterface $finder) {
    
        $someResult = $finder->getRepository(User::class)->find(...);
        return new response('N/A');
    }
    

    【讨论】:

    • 另一个问题,我是新的,它可以工作,但是它返回一些数组,我无法显示它,因为它会引发内存不足错误。应该是教义对象吧?
    • 抱歉打扰了。这是一组教义对象,再次感谢。
    猜你喜欢
    • 1970-01-01
    • 2023-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-09
    • 2017-08-02
    • 2012-06-19
    相关资源
    最近更新 更多