3

私はまだSymfonyにかなり慣れていません。オンライン ポートフォリオに書いたコンポーネントのいくつかのデモンストレーションをセットアップしました。このデモ データを 2 時間ごとにクリアしたいと考えています。私の Web サーバーでは、次のように cron ジョブを設定したいと考えています。

php app/console portfolio:wipe

私は app/src/MyFreelancer/PortfolioBundle/Command/ WipeCommand.phpを作成しました (PortfolioBundle は AppKernel.php に登録されています)。console_command.htmlを変更し、名前空間とコマンド名を変更しました)。

<?php
namespace MyFreelancer\PortfolioBundle\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 WipeCommand extends ContainerAwareCommand
{
    protected function configure()
    {
        $this
            ->setName('maintenance:greet')
            ->setDescription('Greet someone')
            ->addArgument('name', InputArgument::OPTIONAL, 'Who do you want to greet?')
            ->addOption('yell', null, InputOption::VALUE_NONE, 'If set, the task will yell in uppercase letters');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $name = $input->getArgument('name');
        if ($name) {
            $text = 'Hello '.$name;
        } else {
            $text = 'Hello';
        }

        if ($input->getOption('yell')) {
            $text = strtoupper($text);
        }

        $output->writeln($text);
    }
}
?>

ただし、実行すると

php app/console portfolio:wipe test

「こんにちはテスト」を取得する代わりに、取得します

There are no commands defined in the "portfolio" namespace.

どんな助けでも大歓迎です。

4

1 に答える 1