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 function getPage_image_rel() { return $this->hasMany(PageImageRel::className(), ['page_id' => 'id']); }