public function actionDeletePost() { $selection = (array) Yii::$app->request->post('selection'); foreach ($selection as $id) { Post::deleteAll(['id' => $id]); Like::deleteAll(['post_id' => $id]); Comment::deleteAll(['post_id' => $id]); PostTag::deleteAll(['post_id' => $id]); PostNotification::deleteAll(['post_id' => $id]); PostProtected::deleteAll(['post_id' => $id]); } return $this->render('post-manage'); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PostTag::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'count' => $this->count, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
public function actionDelete() { if (Yii::$app->user->isGuest) { $this->redirect(Url::to(['/site/login'])); } if (isset($_POST['id'])) { $id = $_POST['id']; Post::findOne(['id' => $id])->delete(); Like::deleteAll(['post_id' => $id]); Comment::deleteAll(['post_id' => $id]); PostTag::deleteAll(['post_id' => $id]); PostNotification::deleteAll(['post_id' => $id]); PostProtected::deleteAll(['post_id' => $id]); } }
public function actionTags() { $tags = PostTag::find()->orderBy('updated_at DESC')->all(); return $this->render('tags', ['tags' => $tags]); }
/** * Finds the PostTag model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PostTag the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PostTag::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPostTags() { return $this->hasMany(PostTag::className(), ['post_id' => 'id']); }