コード例 #1
0
 /**
  * Creates a new ShortLinks model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new ShortLinks();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
コード例 #2
0
 /**
  * @brief Создание короткой ссылки
  * @param $link
  * @param $title
  * @return string
  */
 public static function saveLink($link, $title = '')
 {
     $model = new ShortLinks();
     $model->link = $link;
     $model->title = $title;
     if ($model->save()) {
         return $model->token;
     }
     Yii::error(['msg' => 'Ошибка создания короткой ссылки', 'data' => ['error' => $model->errors, 'method' => __METHOD__]]);
     return false;
 }