3

I am still pretty new to Symfony. I have set up 'n demonstration of some of the components that I have written on my online portfolio and I want this demo data to be cleared every two hours. On my web server I want to set a cron job like so:

php app/console portfolio:wipe

I have created app/src/MyFreelancer/PortfolioBundle/Command/WipeCommand.php (PortfolioBundle is registered in AppKernel.php) and here is its contents (copied exactly from http://symfony.com/doc/current/cookbook/console/console_command.html and changed the namespace and command name).

<?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);
    }
}
?>

However, when I run

php app/console portfolio:wipe test

Instead of getting "Hello test", I get

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

Any help would be appreciated.

1 Answer 1

1

Your command name is maintenance:greet, so try to call it with php app/console maintenance:greet test

And for your cron job, don't forget to change to the Symfony2 directory before calling php app/console. You can also call the console with the full path : php /var/www/where/is/symfony/app/console ...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.