public function actionArchive($id) { if (Yii::$app->request->isAjax) { $model = $this->findModel($id); $response = []; if (!empty($model)) { $model->is_archive = 1; if ($model->save()) { Page::archive_all_child($model->id); $response['files'] = ['msg' => 'Page Archived successfully', 'id' => $id]; } } else { $response['files'] = ['msg' => 'Error saving data.']; } return json_encode($response); } }
public static function archive_all_child($id) { $child = Page::find()->joinWith('page_rel')->where(['page_self_rels.parent_page_id' => $id])->all(); if (!empty($child)) { foreach ($child as $value) { $value->is_archive = 1; $value->save(); Page::archive_all_child($value->id); } } return true; }