Esempio n. 1
0
 public function actionEdit()
 {
     $data = Yii::$app->request->post('Department');
     $result = array();
     if (is_numeric($data['id']) && $data['id'] > 0) {
         $model = Department::findOne($data['id']);
         if (!$model) {
             $result['status'] = 0;
             $result['message'] = '未找到该记录';
         }
     } else {
         $model = new Department();
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             $result['status'] = 1;
             $result['message'] = '保存成功';
         }
     }
     $errors = $model->getFirstErrors();
     if ($errors) {
         $result['status'] = 0;
         $result['message'] = current($errors);
     }
     return $this->renderJson($result);
 }
Esempio n. 2
0
 public function actionCreate()
 {
     $dept = new Department();
     if ($dept->load(Yii::$app->request->post()) && $dept->save()) {
         return $this->redirect(['index']);
     }
     return $this->render('create', ['dept' => $dept]);
 }
Esempio n. 3
0
 /**
  * Creates a new Department model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Department();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->department_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }