diff --git a/config/db.php b/config/db.php index bc75e61..96f848b 100644 --- a/config/db.php +++ b/config/db.php @@ -1,14 +1,14 @@ 'yii\db\Connection', - 'dsn' => 'mysql:host=localhost;dbname=yii2basic', - 'username' => 'root', - 'password' => '', - 'charset' => 'utf8', - - // Schema cache options (for production environment) - //'enableSchemaCache' => true, - //'schemaCacheDuration' => 60, - //'schemaCache' => 'cache', -]; + + return [ + 'class' => 'yii\db\Connection', + 'dsn' => 'pgsql:host=127.0.0.1;dbname=kite', + 'username' => 'kite', + 'password' => 'qwerty', + 'charset' => 'utf8', + + // Schema cache options (for production environment) + //'enableSchemaCache' => true, + //'schemaCacheDuration' => 60, + //'schemaCache' => 'cache', + ]; diff --git a/controllers/SiteController.php b/controllers/SiteController.php index 9cc0234..e9d895c 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -2,6 +2,7 @@ namespace app\controllers; + use app\models\Subscribe; use yii\web\Controller; use yii\filters\VerbFilter; @@ -28,7 +29,18 @@ public function actionSubscribe() { if (\Yii::$app->request->isPost) { - echo 'ok'; + $model = new Subscribe(); + $model->load(\Yii::$app->request->post(), ''); + $model->time = time(); + $model->domain = \Yii::$app->request->getHostInfo(); + + if ($model->save()) { + return true; + } else { + \Yii::error('Subscribtion didnt saved'); + + return false; + } } } diff --git a/migrations/m180525_143244_create_subscribe_table.php b/migrations/m180525_143244_create_subscribe_table.php new file mode 100644 index 0000000..f824488 --- /dev/null +++ b/migrations/m180525_143244_create_subscribe_table.php @@ -0,0 +1,34 @@ +createTable( + 'subscribe', + [ + 'id' => $this->primaryKey(), + 'name' => $this->string(), + 'email' => $this->string(), + 'domain' => $this->string(), + 'time' => $this->string(), + ] + ); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable('subscribe'); + } + } diff --git a/models/Subscribe.php b/models/Subscribe.php new file mode 100644 index 0000000..1fb6a23 --- /dev/null +++ b/models/Subscribe.php @@ -0,0 +1,38 @@ +