Created
August 27, 2012 11:30
-
-
Save predakanga/3487705 to your computer and use it in GitHub Desktop.
Calling command from controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
this is good man, thanks, that is exactly what i needed