我正在尝试使任务自动化。每周都会自动向某些人发送电子邮件。 我创建了一个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是默认的。 我想我错过了一些配置,但我找不到确切的配置。 谢谢您的帮助,告诉我是否需要更多信息。