public static function add($doc_id, $user_id) { $model = Wishlist::find()->where(['doc_id' => $doc_id, 'user_id' => $user_id])->one(); if (!$model) { $model = new Wishlist(); } $model->user_id = $user_id; $model->doc_id = $doc_id; $model->created_at = time(); $model->updated_at = time(); if ($model->save(FALSE)) { return true; } return false; }
/** * Creates a new Wishlist model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Wishlist(); $model->user_id = Yii::$app->user->id; $model->status = 0; $model->date = date('Y-m-d h:i:s'); if ($model->load(Yii::$app->request->post())) { //$model->assigned_to = implode(',', $model->assigned_to); //var_dump($model); die(); if ($model->save()) { Yii::$app->notification->notify($model->title, $model, $model->user, Yii::$app->controller->id, $model->assigned_to); Yii::$app->session->setFlash('success', 'Item successfully posted.'); } return $this->redirect(['wishlist/index/']); } else { if (Yii::$app->request->isAjax) { return $this->renderAjax('_form', ['model' => $model]); } else { return $this->render('create', ['model' => $model]); } } }