/** * Creates a new DcmdTaskCmd model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->getIdentity()->admin != 1) { Yii::$app->getSession()->setFlash('success', NULL); Yii::$app->getSession()->setFlash('error', "对不起,你没有权限!"); return $this->redirect(array('dcmd-task-cmd/index')); } $model = new DcmdTaskCmd(); if (Yii::$app->request->post()) { $model->utime = date('Y-m-d H:i:s'); $model->ctime = $model->utime; $model->opr_uid = Yii::$app->user->getId(); if ($model->load(Yii::$app->request->post()) && $model->save()) { Yii::$app->getSession()->setFlash('success', "添加成功!"); return $this->redirect(['view', 'id' => $model->task_cmd_id]); } $err_str = ""; foreach ($model->getErrors() as $k => $v) { $err_str .= $k . ":" . $v[0] . "<br>"; } Yii::$app->getSession()->setFlash('error', "添加失败:" . $err_str); } return $this->render('create', ['model' => $model]); }