/** * Deletes a page after a form submission. * * @param int $id an id of a page to delete. Must match id in posted form. * @throws InvalidCallException if provided id does not match id in posted form. */ public function actionDelete($id) { $pageId = Yii::$app->getRequest()->post('id'); if ($pageId != $id) { throw new InvalidCallException("Invalid form submitted. Page with id: '{$id}' not deleted."); } $model = Page::findOne($id); if ($model) { if ($model->delete()) { Yii::$app->getSession()->setFlash('success', Yii::t('cms', 'Page deleted.')); } else { Yii::$app->getSession()->setFlash('info', Yii::t('cms', 'Page not deleted, please try again.')); } } else { Yii::$app->getSession()->setFlash('error', Yii::t('cms', 'Page with id "{id}" not found.', ['id' => $id])); } return $this->redirect(['index']); }