繁体   English   中英

将日光浴室与 Solr 一起使用

[英]Using Solarium with Solr

我正在尝试将 Solarium (NelmioSolariumBundle) 与 Solr 一起使用,但出现以下错误消息:

Service "solarium.client" not found: even though it exists in the app's container, the container
inside "App\Controller\solariumController" 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. Try using dependency injection instead.

这是我的 controller

<?php


namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class solariumController extends AbstractController
{

    /**
     * @Route ("/solariums", name="solariums")
     */
    public function solariumSearch(){

        $client = $this->get('solarium.client');
        $select = $client->createSelect();
        $select->setQuery('brandon');
        $results = $client->select($select);

        return $this->render('pages/solarium.html.twig',[
            '$results'
        ]);

    }
}

你有什么想法吗?

谢谢 !

在构造函数中注入客户端:

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class solariumController extends AbstractController
{
    /** @var \Solarium\Client */
    private $client;

    public function __construct(\Solarium\Client $client) {
       $this->client = $client;
    }

    /**
     * @Route ("/solariums", name="solariums")
     */
    public function solariumSearch() {

        $select = $this->client->createSelect();
        $select->setQuery('brandon');
        $results = $this->client->select($select);

        return $this->render('pages/solarium.html.twig',[
            '$results'
        ]);

    }
}

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM