示例#1
0
 /**
  * Deletes an existing CourseType model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     try {
         //	$this->findModel($id)->delete();
         $ct = $this->findModel($id);
         //$crs = $ct->courses;
         //$cls = $ct->clsses;
         $crs_count = Course::find()->where(['crs_ct_id' => $id])->count();
         $cls_count = Clss::find()->where(['clss_ct_id' => $id])->count();
         Yii::$app->session->setFlash('message', "You cannot delete this record!");
         if ($crs_count == 0 && $cls_count == 0) {
             $ct->delete();
             //	Yii::$app->session->setFlash('success','The car was successfully deleted');
             //		foreach (Yii::$app->session->getAllFlashes() as $key => $message) {
             echo '<div class="alert alert-success">' . 'The car was successfully deleted' . '</div>';
             //	}
         } else {
             //header("HTTP/1.0 400 Relation Restriction");
             Yii::$app->session->setFlash('message', "You cannot delete this record!");
         }
     } catch (CDbException $e) {
         if ($e->errorInfo[1] == 1451) {
             header("HTTP/1.0 400 Relation Restriction");
             echo "Your error message.\n";
         } else {
             throw $e;
         }
         // 		} catch (IntegrityException $e) {
         //   	if($e->getCode()===23000){
         //You can have nother error handling
         //        		header("HTTP/1.0 400 Relation Restriction");
         // 	}else{
         //		throw $e;
         //}
     }
     return $this->redirect(['index']);
 }
示例#2
0
文件: Teacher.php 项目: AtaBashir/ams
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getClsses()
 {
     return $this->hasMany(Clss::className(), ['clss_tchr_id' => 'tchr_id']);
 }