Php Symfony-在cron选项卡中调用原则

Php Symfony-在cron选项卡中调用原则,php,symfony,cron,Php,Symfony,Cron,嘿,伙计们,我想知道如何做cron选项卡,但cron选项卡必须更新数据库,所以我需要 $this->getDoctrine()->getManager() 但为此,我需要扩展控制器,但我已经扩展了命令 所以我想有一种方法可以扩展这两种功能吗?我是否必须使用sql命令?或者使用cron选项卡更新数据库的其他方法 在这里,您可以找到我的find并查看我需要什么: use Symfony\Component\Console\Command\Command; use Symfony\Component\

嘿,伙计们,我想知道如何做cron选项卡,但cron选项卡必须更新数据库,所以我需要

$this->getDoctrine()->getManager()

但为此,我需要扩展
控制器
,但我已经扩展了
命令

所以我想有一种方法可以扩展这两种功能吗?我是否必须使用sql命令?或者使用cron选项卡更新数据库的其他方法

在这里,您可以找到我的find并查看我需要什么:

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class MessageController extends Command
{
    protected function configure () {
        $this->setName('app:notification');
        $this->setDescription("Permet juste d'envoyer les notifications");
        $this->setHelp("Je serai affiche si on lance la commande app/console app:notification -h");
    }

    public function execute (InputInterface $input, OutputInterface $output) {
        //HERE I WANT TO DO : $this->getDoctrine()->getManager();
        $output->writeln('!');
    }
}

您可以改为扩展ContainerWareCommand并使用

$this->getContainer()->get('doctrine')->getManager()

我认为这是可行的thx:)我不能接受9分钟的响应,所以请稍等一点,我将它设置为有效的thx很多人:)避免在Symfony 4中直接使用容器:最好通过DIC将条令注册表注入构造函数。