Exemplo n.º 1
0
 /**
  * Creates a new Bookmark model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Bookmark();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Exemplo n.º 2
0
 public function actionAddToBookmarks($id)
 {
     $bookmark = new Bookmark();
     $n = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'advert_id' => $id])->one();
     if (!empty($n)) {
         $n->delete();
         echo 'Add to bookmarks';
     } else {
         $bookmark->user_id = Yii::$app->user->identity->getId();
         $bookmark->advert_id = $id;
         $bookmark->save();
         echo 'Delete ' . 'from bookmarks';
     }
 }
Exemplo n.º 3
0
 public function actionAddToBookmarks($id)
 {
     $bookmark = new Bookmark();
     $n = Bookmark::find()->where(['user_id' => Yii::$app->user->identity->getId(), 'advert_id' => $id])->all();
     //        var_dump(!empty($n)); die;
     if (!empty($n)) {
         echo Json::encode([]);
     } else {
         $bookmark->user_id = Yii::$app->user->identity->getId();
         $bookmark->advert_id = $id;
         $bookmark->save();
         echo Json::encode([]);
     }
 }