Skip to content

Instantly share code, notes, and snippets.

@cordoval
Forked from predakanga/gist:3487705
Created August 27, 2012 11:32
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cordoval/3487715 to your computer and use it in GitHub Desktop.
Save cordoval/3487715 to your computer and use it in GitHub Desktop.
Calling command from controller
<?php
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArrayInput;
/**
* @Route("/test")
*/
class SomeController extends Controller
{
/**
* @Route("/command")
*/
public function someAction()
{
// Create the application, so that it can collect all the commands
$application = new Application($this->getContainer()->get('kernel'));
$application->setAutoExit(false);
// The input interface should contain the command name, and whatever arguments the command needs to run
$input = new ArrayInput(array("doctrine:schema:update"));
$output = new MemoryWriter();
// Run the command
$retval = $application->run($input, $output);
if(!$retval)
{
echo "Command executed successfully!\n";
}
else
{
echo "Command was not successful.\n";
}
var_dump($output->getOutput());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment