public function beforeAction($action) { if (parent::beforeAction($action)) { if ($action->id !== 'create') { if (is_string($this->db)) { $this->db = Yii::$app->get($this->db); } if (!$this->db instanceof Connection) { throw new Exception("The 'db' option must refer to the application component ID of a DB connection."); } if ($this->db->schema->getTableSchema(User::tableName(), true) === null) { throw new Exception("The '" . User::tableName() . "' table does not exist."); } } $version = Yii::getVersion(); echo "Maddoger`s User Creation tool (based on Yii v{$version})\n\n"; return true; } else { return false; } }
/** * @return \yii\db\ActiveQuery */ public function getUsers() { return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable(User::tableName(), ['item_name' => 'name']); }