Answer the question
In order to leave comments, you need to log in
How to solve the error You have requested a non-existent service "App\Entity\Song"?
Symphony 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);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question