簡體   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