/** * Creates a new Country model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Country(); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * * @param string $fn Absolute Path to Import Filename, if not set, the system will use a default import file loaded in the data folder in the root of the extension * @param type $delimiter * @return type */ public function actionCountries($fn = NULL) { //Set filename to default location if (!isset($fn)) { $fn = \Yii::getAlias('@vendor') . '/humanized/yii2-location/data/countries/countries.csv'; } $file = fopen($fn, "r"); while (!feof($file)) { $record = fgetcsv($file, 0); if (!isset($record[0])) { break; } $country = new Country(['iso_2' => $record[0], 'iso_3' => $record[1], 'iso_numerical' => $record[2], 'has_postcodes' => $record[3]]); $country->save(); } }