Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Yii2 Migrate command called by Web controller
public function actionMigrate()
{
    // Keep current application
    $oldApp = \Yii::$app;
    // Load Console Application config
    $config = require \Yii::getAlias('@app'). '/config/console.php';
    new \yii\console\Application($config);
    $result = \Yii::$app->runAction('migrate', ['migrationPath' => '@app/migrations/', 'interactive' => false]);
    // Revert application
    \Yii::$app = $oldApp;
    return;
}

Above sample code is for yii2-app-basic template, you could change path for yii2-app-advanced template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment