public function actionNews($news_id) { $news = News::find()->where(['id' => $news_id, 'is_published' => 1])->asArray()->one(); if ($news) { $news['categories'] = CategoryRelations::get_news_categories_names($news['id']); return $this->render('news', compact('news')); } }
/** * Deletes an existing News model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param integer $id * @return mixed */ public function actionDelete($id) { CategoryRelations::deleteAll(['news_id' => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); }
/** * @return \yii\db\ActiveQuery */ public function getCategoryRelations() { return $this->hasMany(CategoryRelations::className(), ['news_id' => 'id']); }