yii\console\controllers\MigrateController::beforeAction PHP Метод

beforeAction() публичный Метод

This method is invoked right before an action is to be executed (after all possible filters.) It checks the existence of the [[migrationPath]].
public beforeAction ( Action $action ) : boolean
$action yii\base\Action the action to be executed.
Результат boolean whether the action should continue to be executed.
    public function beforeAction($action)
    {
        if (parent::beforeAction($action)) {
            if ($action->id !== 'create') {
                $this->db = Instance::ensure($this->db, Connection::className());
            }
            return true;
        } else {
            return false;
        }
    }

Usage Example

 public function beforeAction($action)
 {
     $oldPath = $this->migrationPath;
     $this->migrationPath = $this->defaultMigrationPath;
     if (parent::beforeAction($action)) {
         $this->stdout('Migration files will be searched in folders: ' . PHP_EOL);
         $this->migrationPath = $oldPath;
         if ($this->moduleId) {
             $this->migrationPath = $this->getMigrationPath($this->moduleId);
         }
         if ($this->migrationPath) {
             $this->migrationPaths[] = $this->migrationPath;
         } else {
             $this->migrationPaths[] = $this->defaultMigrationPath;
             foreach (Yii::$app->modules as $name => $module) {
                 $this->migrationPaths[] = $this->getMigrationPath($name);
             }
         }
         $this->migrationPaths = array_unique($this->migrationPaths);
         for ($i = 0; $i < count($this->migrationPaths); $i++) {
             $this->migrationPaths[$i] = Yii::getAlias($this->migrationPaths[$i]);
             $this->stdout(' - ' . $this->migrationPaths[$i] . PHP_EOL);
         }
         $this->stdout(PHP_EOL);
         return true;
     } else {
         return false;
     }
 }
All Usage Examples Of yii\console\controllers\MigrateController::beforeAction