Reputation: 1624
I want to execute this command
php app/console doctrine:schema:update
from the controles without use exec
php function,
Any comment will be use full to me.
Thanks!!!
Upvotes: 11
Views: 10879
Reputation: 1624
Thanks to every one,
I used this code
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
//Create de Schema
$options = array('command' => 'doctrine:schema:update',"--force" => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
//Loading Fixtures
$options = array('command' => 'doctrine:fixtures:load',"--append" => true);
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
and in this link, there are some information maybe will be usefull for others
Thanks!!!
Upvotes: 13
Reputation: 13214
If you are looking here, on the bottom there is an example of how to execute a command from within symfony code.
Please also mind the note on the end saying that it might not be a good idea to use a command within your code.
As said, the following code should be used with care. I wouldn't use it for the reasons statet in the symfony doc, but it works.
When using the following code within your controller, you are able to execute a command:
$kernel = $this->get('kernel');
$application = new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
$application->setAutoExit(false);
$options = array('command' => 'list');
$application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
If you need the output, you have to either use an existing class implementing OutputInterface or create your own depending on your needs.
Upvotes: 15