public function actionEdit() { $data = Yii::$app->request->post('Channel'); $result = array(); if (is_numeric($data['id']) && $data['id'] > 0) { $model = Channel::findOne($data['id']); if (!$model) { $result['status'] = 0; $result['message'] = '未找到该记录'; } } else { $model = new Channel(); } 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); }
/** * Creates a new Channel model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Channel(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }