/**
  * Creates a new ShortLinksClick model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ShortLinksClick();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 public static function findByToken($token)
 {
     $model = ShortLinks::find()->where(['token' => $token])->one();
     if ($model) {
         $click = new ShortLinksClick();
         $click->short_links_id = $model->id;
         if (!$click->save()) {
             Yii::error(['msg' => 'Ошибка записи статистики клика', 'data' => ['error' => $model->errors, 'method' => __METHOD__]]);
         }
         $model->count_click += 1;
         $model->save();
         // Запишем ссылку в куки
         $cookies = Yii::$app->response->cookies;
         // добавление новой куки в HTTP-ответ
         $cookies->add(new \yii\web\Cookie(['name' => 'short_link_id', 'value' => $model->id, 'expire' => time() + 60 * 60 * 24 * 7]));
         return $model->link;
     }
     return false;
 }