Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

execute php app/console doctrine:schema:update from controller symfony 2

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!!!

like image 429
JERC Avatar asked Mar 06 '12 17:03

JERC


2 Answers

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.

like image 66
Sgoettschkes Avatar answered Nov 17 '22 09:11

Sgoettschkes


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!!!

like image 31
JERC Avatar answered Nov 17 '22 07:11

JERC