This only happens on my production server. On my dev box the command is working as expected.
When I call my method in a controller, I can access the custom repository methods just fine. e.g.:
$em = $this->getDoctrine()->getManager();
$myData = $em->getRepository('AcmeUserBundle:User')->customMethod();
When I request the same repository and method in my command, I get:
Undefined method 'customMethod'. The method name must start with either findBy or findOneBy!
That tells me it's not seeing the repository defined in my User entity.
Here is my command code:
<?php
namespace ACME\UserBundle\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;
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 also not getting this written to the logfile
$em = $this->getContainer()->get("doctrine")->getManager();
$myData = $em->getRepository('ACMEUserBundle:User')->customMethod();
$output->writeln($myData);
}
}
How is retrieving the repository inside of a command different from a controller? I know to use ->getContainer(), but otherwise?
Since the logger isn't logging, is there a problem with getContainer()?
doctrine.orm
ordoctrine.orm.default_entity_manager
? I would try using these instead of justdoctrine
unless you have renamed it.