symfony2 - Repository method found in Controller, but not in Command -
symfony2 - Repository method found in Controller, but not in Command -
this happens on production server. on dev box command working expected.
when phone call method in controller, can access custom repository methods fine. e.g.:
$em = $this->getdoctrine()->getmanager(); $mydata = $em->getrepository('acmeuserbundle:user')->custommethod();
when request same repository , method in command, get:
undefined method 'custommethod'. method name must start either findby or findoneby!
that tells me it's not seeing repository defined in user entity.
here command code:
<?php namespace acme\userbundle\command; utilize symfony\bundle\frameworkbundle\command\containerawarecommand; utilize symfony\component\console\input\inputargument; utilize symfony\component\console\input\inputinterface; utilize symfony\component\console\input\inputoption; utilize symfony\component\console\output\outputinterface; class mycommand extends containerawarecommand { protected function configure() { $this->setname("user:getmydata"); } protected function execute(inputinterface $input, outputinterface $output) { $logger = $this->getcontainer()->get('logger'); $logger->info('mycommand called'); // i'm not getting written logfile $em = $this->getcontainer()->get("doctrine")->getmanager(); $mydata = $em->getrepository('acmeuserbundle:user')->custommethod(); $output->writeln($mydata); } }
how retrieving repository within of command different controller? know utilize ->getcontainer(), otherwise?
since logger isn't logging, there problem getcontainer()?
looks have wrong service name doctrine's orm.
change service name
$this->get('doctrine')
to
$this->get('doctrine.orm.default_entity_manager')
you must specify right service name orm in order access repository methods defined in configuration. repositories mounted orm , not doctrine itself.
documentation on custom repositories
symfony2 console repository
Comments
Post a Comment