Symfony2: call a route inside a command

I have a Command class from which I want to call a route to execute a controller.

MyClassCommand extends ContainerAwareCommand
{
    protected configure()
    {

    }

    protected execute()
    {

    }
}

How do I call a route from the method execute(), which will simply call an Action?

Thanks

Answers


A bundle can do this yet: PhaxBundle.

Declare your controller as a service, and simply call something like this in command:

$ php app/console phax:action yourcontroller youraction -p parametername:value

You should put your code that you want to execute into an extra class, make it a service, then using it from both your controller and your command.

Then in your command class you can call your service like this :

$this->getApplication()->getKernel()->getContainer()->get('service');


Need Your Help

how to change a single letter in filenames all over the file system?

linux file-io command-line filesystems

i have hundreds of files with special characters ('æ', 'ø' and 'å') in their filenames.

How to tell maven to get MAVEN_OPTS from specific file?

maven

mvn command, among others, have following options: