Skip to content

Instantly share code, notes, and snippets.

@predakanga
Created August 27, 2012 11:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save predakanga/3487705 to your computer and use it in GitHub Desktop.
Save predakanga/3487705 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());
}
}
@cordoval
Copy link

cordoval commented Sep 2, 2012

this is good man, thanks, that is exactly what i needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment