public function actionDelete($id) { PageSelfRels::updateAll(['parent_page_id' => 0], 'parent_page_id = ' . $id); PageSelfRels::deleteAll(['page_id' => $id]); $images = PageImageRel::findAll(['page_id' => $id]); if (!empty($images)) { foreach ($images as $key => $value) { unlink(\Yii::getAlias('@webroot') . '/uploads/' . $value->image); } } PageImageRel::deleteAll(['page_id' => $id]); PageCategoryRel::deleteAll(['page_id' => $id]); Post::deleteAll(['page_id' => $id]); $this->findModel($id)->delete(); return $this->redirect(['index']); }
public static function update_page_self_rel($model) { PageSelfRels::deleteAll(['page_id' => $model->page_id]); foreach ($model->parent_page_id as $key => $value) { $new_model = new PageSelfRels(); $new_model->page_id = $model->page_id; $new_model->parent_page_id = $value; if ($new_model->save()) { } else { throw new NotFoundHttpException('The requested page does not exist.'); } } return true; }