示例#1
0
 /**
  * Creates a new Subjects model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Subjects();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->SubjectId]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
示例#2
0
 public function actionAdd()
 {
     Yii::$app->response->format = Response::FORMAT_JSON;
     $request = \Yii::$app->request;
     $data = $request->post();
     if ($data['name'] == '') {
         return ['status' => 0, 'message' => 'Không được để trống tên'];
     }
     $data['created_at'] = time();
     $data['updated_at'] = time();
     try {
         $model = new Subjects();
         $model->attributes = $data;
         if ($model->save()) {
             return ['status' => 1, 'message' => 'Thành công'];
         }
         return ['status' => 0, 'message' => 'Có lỗi xảy ra'];
     } catch (Exception $ex) {
         return ['status' => 0, 'message' => 'Có lỗi xảy ra'];
     }
 }