@great_77

Как решить ошибку You have requested a non-existent service «App\Entity\Song»?

Symfony 4.4:
<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use App\Entity\Song;

class ImportSongsDataToSongIndex extends ContainerAwareCommand
{
	protected static $defaultName = 'app:import-songs-data-to-elastic';

	protected function configure()
    {
        $this
            ->setDescription(
                'Importe songs'
            );
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $output->writeln('Importing songs in the index');
        $songs = $this->getSongs();
        $this->createSongDocument($songs);
    }

    private function getSongs()
    {
    	$song = $this->getContainer()
    		->get(Song::class)
    		->findAll();
    }

    private function createSongDocument(array $songs)
    {
    	$documents = [];

    	foreach($songs as $song) {

    		// Create a document
	        $track = [
	            'id' => $song->getId(),
	            'name' => $song->getName(),
	            'description' => $song->getDescription(),
	            'name_not_analyzed' => $name
	        ];

	        // First parameter is the id of document.
	        $documents[] = new \Elastica\Document($id, $track);
    	}
    }
}
  • Вопрос задан
  • 199 просмотров
Решения вопроса 1
@great_77 Автор вопроса
$song = $this->getContainer()
->get('doctrine')
->getRepository(Song::class)
->findAll();
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы