I would like to use ArrayCollection
in a custom symfony command.
But my way is throwing an error
The class 'Doctrine\Common\Collections\ArrayCollection' was not found in the chain configured namespaces AppBundle\Entity
My command
<?php
namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Doctrine\Common\Collections\ArrayCollection;
use AppBundle\Entity\Gameworld;
class MyCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('get:gw')
->setDescription('Populate gameworld')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$em = $this->getContainer()->get('doctrine')->getManager();
$output->writeln('<info>Get current Gameworlds</info>');
$gws = $em->getRepository('AppBundle:Gameworld')->findAll();
$gws = new ArrayCollection($gws);
/* rest of the command */
}
}
I tried to do new \Doctrine\Common\Collections\ArrayCollection($gws);
But the error is still there.
Hope you may help.