/** * Creates a new Notice model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Notice(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function actionCreate() { $model = new Notice(); if ($model->load(Yii::$app->request->post())) { // 获取用户输入的数据,验证并保存 $rids = $model->rids; $model->rids = ',' . implode(',', $model->rids) . ','; $model->uid = $this->user->id; $model->create_time = date('Y-m-d H:i:s'); if ($model->save()) { $this->redirect('/notice/index'); } } $roles = Role::findBySql('SELECT * FROM ' . Role::tableName() . ' where id > 1')->all(); return $this->render('create', array('model' => $model, 'roles' => $roles)); }
/** *新增和修改提交 * @return array */ public function actionSubmit() { $params = Yii::$app->request->post(); if (isset($params["notice_id"])) { $model = $this->findModel($params["notice_id"]); } else { $model = new Notice(); $params["create_at"] = date("Y-m-d"); $params["user_id"] = Yii::$app->user->getId(); } $data = array(); //yii自动生成的form参数是Enterprise["name"]这种形式,获取后就会是在一个Enterprise中 $data["Notice"] = $params; \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; if ($model->load($data) && $model->save()) { return ["success" => true]; } else { return ["success" => false, "error_code" => 1]; } }