protected function loadModel($id) { if (($model = Department::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDel($id) { $result = array(); $model = Department::findOne($id); if (Record::find()->where('department_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); }
public function getIsChief() { return Department::findOne(['chief_id' => $this->id]) !== null; }
/** * Finds the Department model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @param integer $faculty_id * @return Department the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id, $faculty_id) { if (($model = Department::findOne(['id' => $id, 'faculty_id' => $faculty_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }