1

I'm trying to use Solarium (NelmioSolariumBundle) with Solr and I have this error message:

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.

Here is my 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'
        ]);

    }
}

Do you have any idea please?

Thanks !

Leprechaun
  • 759
  • 5
  • 14
Brandys
  • 354
  • 1
  • 3
  • 15

1 Answers1

2

Inject client in constructor:

<?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'
        ]);

    }
}
Leprechaun
  • 759
  • 5
  • 14
  • It works, thx ! Now I just have to find how to make a search form and a upload form ! – Brandys Jun 10 '20 at 07:51
  • It works, but I get a deprecation warning. It is described here: https://stackoverflow.com/q/62570493/7424979 Any ideas how to solve? – meistermuh Nov 10 '20 at 12:56