Last active
August 24, 2018 02:11
-
-
Save susilolab/03bdd03a0fcab61d447a255c76137ef9 to your computer and use it in GitHub Desktop.
Run yii1 console 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 | |
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