Commit 2929939cbb35c0da53feca8d0b3b2d1ab2af518f

Authored by Alexey Boroda
1 parent 9568083b

-Kind of ready

config/db.php
1 1 <?php
2   -
3   -return [
4   - 'class' => 'yii\db\Connection',
5   - 'dsn' => 'mysql:host=localhost;dbname=yii2basic',
6   - 'username' => 'root',
7   - 'password' => '',
8   - 'charset' => 'utf8',
9   -
10   - // Schema cache options (for production environment)
11   - //'enableSchemaCache' => true,
12   - //'schemaCacheDuration' => 60,
13   - //'schemaCache' => 'cache',
14   -];
  2 +
  3 + return [
  4 + 'class' => 'yii\db\Connection',
  5 + 'dsn' => 'pgsql:host=127.0.0.1;dbname=kite',
  6 + 'username' => 'kite',
  7 + 'password' => 'qwerty',
  8 + 'charset' => 'utf8',
  9 +
  10 + // Schema cache options (for production environment)
  11 + //'enableSchemaCache' => true,
  12 + //'schemaCacheDuration' => 60,
  13 + //'schemaCache' => 'cache',
  14 + ];
... ...
controllers/SiteController.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace app\controllers;
4 4  
  5 + use app\models\Subscribe;
5 6 use yii\web\Controller;
6 7 use yii\filters\VerbFilter;
7 8  
... ... @@ -28,7 +29,18 @@
28 29 public function actionSubscribe()
29 30 {
30 31 if (\Yii::$app->request->isPost) {
31   - echo 'ok';
  32 + $model = new Subscribe();
  33 + $model->load(\Yii::$app->request->post(), '');
  34 + $model->time = time();
  35 + $model->domain = \Yii::$app->request->getHostInfo();
  36 +
  37 + if ($model->save()) {
  38 + return true;
  39 + } else {
  40 + \Yii::error('Subscribtion didnt saved');
  41 +
  42 + return false;
  43 + }
32 44 }
33 45 }
34 46  
... ...
migrations/m180525_143244_create_subscribe_table.php 0 → 100644
  1 +<?php
  2 +
  3 + use yii\db\Migration;
  4 +
  5 + /**
  6 + * Handles the creation of table `subscribe`.
  7 + */
  8 + class m180525_143244_create_subscribe_table extends Migration
  9 + {
  10 + /**
  11 + * {@inheritdoc}
  12 + */
  13 + public function safeUp()
  14 + {
  15 + $this->createTable(
  16 + 'subscribe',
  17 + [
  18 + 'id' => $this->primaryKey(),
  19 + 'name' => $this->string(),
  20 + 'email' => $this->string(),
  21 + 'domain' => $this->string(),
  22 + 'time' => $this->string(),
  23 + ]
  24 + );
  25 + }
  26 +
  27 + /**
  28 + * {@inheritdoc}
  29 + */
  30 + public function safeDown()
  31 + {
  32 + $this->dropTable('subscribe');
  33 + }
  34 + }
... ...
models/Subscribe.php 0 → 100644
  1 +<?php
  2 +
  3 + namespace app\models;
  4 +
  5 + use yii\db\ActiveRecord;
  6 +
  7 + /**
  8 + * Class Subscribe
  9 + *
  10 + * @property string $email
  11 + * @property string $name
  12 + * @property string $domain
  13 + * @property int $time
  14 + * @package app\models
  15 + */
  16 + class Subscribe extends ActiveRecord
  17 + {
  18 + public function rules()
  19 + {
  20 + return [
  21 + [
  22 + [ 'email' ],
  23 + 'email',
  24 + ],
  25 + [
  26 + [ 'name' ],
  27 + 'string',
  28 + ],
  29 + [
  30 + [
  31 + 'domain',
  32 + 'time',
  33 + ],
  34 + 'safe',
  35 + ],
  36 + ];
  37 + }
  38 + }
0 39 \ No newline at end of file
... ...