public function actionDeleteProperty($id) { if (Yii::app()->user->isGuest) { throw new CHttpException(403, 'You are not authorized.'); } $property = PropertyApi::getPropertyById($id); if ($property->user_id !== Yii::app()->user->id) { throw new CHttpException(403, 'You are not authorized.'); } if (PropertyApi::deletePropertyById($property->id)) { Yii::app()->user->setFlash('success', 'The property was removed successfully'); } else { Yii::app()->user->setFlash('error', 'The property could not be removed. Please contact the admin.'); } $this->redirect('/properties'); }