ContainerAwareCommand with get doctrine

时间:2014-08-19 12:08:38

标签: php symfony doctrine-orm cron doctrine

我尝试在cron作业中使用doctrine,我尝试从堆栈中遵循一些建议并找到使用

  

ContainerAwareCommand

但是内核似乎有问题,每次都找不到他,这里是我简单的cron namespace Site \ Bundle \ AdminBundle \ Services \ Cron;

class EuropatourCron extends \Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
{
    protected function configure() {
        parent::configure();
        $this->setName("updateInfo")
                ->setDescription("Update db with offert from Europatours.at")
                ->addArgument('install');
    }

    protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) {
        $toDo = $this->getContainer()->get('doctrine')->getRepository('SiteAdminBundle:Europatoursofertacron')->findBy(array(
            'status' => 0
        ));

        $output->writeln(\Doctrine\Common\Util\Debug::dump($toDo));
    }
}

这是我来自test的文件:

// application.php
require_once 'vendor/autoload.php';
require_once 'src/Site/Bundle/AdminBundle/Services/Crons/EuropatourCron.php';
use Site\Bundle\AdminBundle\Services\Cron\EuropatourCron;
use Symfony\Component\Console\Application;

$application = new Application();
$application->add(new EuropatourCron);
$application->run();

我试着找到了这个错误的共鸣,但没有找到:

  

PHP致命错误:在/var/www/europatur/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Command/ContainerAwareCommand.php中调用未定义的方法Symfony \ Component \ Console \ Application :: getKernel()第42行

1 个答案:

答案 0 :(得分:5)

您不需要创建文件来运行命令,您可以忽略您的application.php,只需从命令行运行(在项目路径中)

php app/console updateInfo