public function actionDel($id) { $result = array(); $model = Channel::findOne($id); if (Record::find()->where('channel_id=' . $id . '')->exists() || ChannelCost::find()->where('channel_id=' . $id . '')->exists()) { $model->enabled = 0; $model->update(); $result['status'] = 1; $result['message'] = '该渠道已关联数据,不能删除,已经禁用!'; } else { $model->delete(); $result['status'] = 1; $result['message'] = '删除成功'; } return $this->renderJson($result); }
/** * Finds the Channel model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Channel the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Channel::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }