I'm trying to enhance an old project built with symfony 3.2 but i'm facing a weird issue. I'm just trying to get some data in my controller to send it to the view. But, for some reason i can't reach the repository function i made from my controller. Here is the code:
The Repository
class CommandeRepository extends EntityRepository
{
...
public function getSPSExpe()
{
$dql = 'SELECT .....(not showing it for security reason)';
$em = $this->getDoctrine()->getManager('default');
$query = $em->createQuery($dql);
$query->setParameters(array(
'idSite' => 201,
'idEtat' => 9
));
$results = $query->getResult();
return $results;
}
}
The Controller
class ExpeditionController extends Controller
{
...
public function expeditionSPS(CommandeRepository $repo)
{
$results = $repo->getSPSExpe();
return $this->render('WorkflowFrontOfficeBundle:Expedition:expeditionSPS.html.twig',
['results' => $results]);
}
}
It seems fine right??! but i get this error : Controller ... requires that you provide a value for the "$repo" argument. Either the argument is nullable and no null value has been provided, no default value has been provided or because there is a non optional argument after this one
And when i set CommandeRepository $repo = null as a parameter i get: calling getSPSExpe() on null ....
Do you have any idea about what should be done here? Thanks a lot for your time.
Thanks to Delboy i looked a bit in service container of older symfony versions. I executed "php bin/console debug:container repository and got:
Information for Service "doctrine.orm.container_repository_factory"
===================================================================
------------------ ----------------------------------------------------------------------
Option Value
------------------ ----------------------------------------------------------------------
Service ID doctrine.orm.container_repository_factory
Class Doctrine\Bundle\DoctrineBundle\Repository\ContainerRepositoryFactory
Tags -
Public no
Synthetic no
Lazy no
Shared yes
Abstract no
Autowired no
Autowiring Types -
------------------ ----------------------------------------------------------------------
Couldn't find yet how to set autowired to yes for this class.