Skip to content

Instantly share code, notes, and snippets.

@susilolab
Last active August 24, 2018 02:11
Show Gist options
  • Save susilolab/03bdd03a0fcab61d447a255c76137ef9 to your computer and use it in GitHub Desktop.
Save susilolab/03bdd03a0fcab61d447a255c76137ef9 to your computer and use it in GitHub Desktop.
Run yii1 console command from controller
<?php
class DemoController extends Controller
{
private function migrate($cmd=array()) {
$commandPath = Yii::app()->getBasePath() . '/commands';
$runner = new CConsoleCommandRunner;
$runner->addCommands($commandPath);
$commandPath = Yii::getFrameworkPath() . '/cli/commands';
$runner->addCommands($commandPath);
$args = array('yiic', 'migrate', 'history');
if(count($cmd))
$args = $cmd;
ob_start();
$runner->run($args);
return htmlentities(ob_get_clean(), null, Yii::app()->charset);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment