0

我正在尝试自动执行一项任务。这是每周自动向某些人发送电子邮件。我创建了一个 MailController,在它内部实现了一个发送电子邮件的功能。我现在要做的是让我的应用程序每周或每月自动调用该功能。

我尝试的是实现一个新命令,该命令将执行我的函数,然后制作一个脚本来重复该命令。

<?php

namespace App\Command;

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


    class MailCommand extends Command {

        protected function configure () {
            $defaultName = 'app:mailAuto';

            $this->setDescription("Permet d'envoyer des mails automatiquement lorsque le parc n'est pas à jour");

            $this->setHelp("Je serai affiche si on lance la commande bin/console app:mailAuto -h");

        }

        public function execute (InputInterface $input, OutputInterface $output) {
            // $controller = new MailController();
            // $controller->warningMailAction();
            $output->writeln('coucou !');
        }
    }

执行我创建的命令时,我收到以下消息:

In FileLoader.php line 166:
  The autoloader expected class "App\Command\commandeMailAuto" to be defined
  in file "/var/www/html/ParcAuto/vendor/composer/../../src/Command/commandeM
  ailAuto.php". The file was found but the class was not in it, the class nam
  e or namespace probably has a typo in /var/www/html/ParcAuto/config/service
  s.yaml (which is loaded in resource "/var/www/html/ParcAuto/config/services
  .yaml").

In DebugClassLoader.php line 213:
  The autoloader expected class "App\Command\commandeMailAuto" to be defined
  in file "/var/www/html/ParcAuto/vendor/composer/../../src/Command/commandeM
  ailAuto.php". The file was found but the class was not in it, the class nam
  e or namespace probably has a typo.

我正在运行 symfony 4.3.2,我试图调用的控制器扩展了 AbstractController,我的 services.yaml 是默认的。我想我错过了一些配置,但我无法找出确切的配置。感谢您的帮助,如果您需要更多信息,请告诉我。

4

0 回答 0