/** * Creates a new AuthAssignment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new AuthAssignment(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'item_name' => $model->item_name, 'user_id' => $model->user_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new AuthAssignment model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('createAuthAssignment')) { $model = new AuthAssignment(); if ($model->load(Yii::$app->request->post())) { $model->created_at = time(); $model->save(); return $this->redirect(['view', 'item_name' => $model->item_name, 'user_id' => $model->user_id]); } else { return $this->render('create', ['model' => $model]); } } else { throw new ForbiddenHttpException(); } }
public function actionUpdate() { $id = Yii::$app->request->get('id', 0); $error = ''; $user = new User(); $model = $this->findModel($id); $data['_csrf'] = Yii::$app->request->post('_csrf', ''); $data['User'] = Yii::$app->request->post(); if (isset($data['User']['submit'])) { $data['User']['update_date'] = time(); $data['User']['user_update'] = \Yii::$app->user->id; if ($model->load($data) && $model->save()) { $this->findAuth($id)->delete(); $auth = new AuthAssignment(); $dataAuth['_csrf'] = $data['_csrf']; $dataAuth['AuthAssignment']['item_name'] = $data['User']['group']; $dataAuth['AuthAssignment']['user_id'] = $id; $dataAuth['AuthAssignment']['created_at'] = time(); $auth->load($dataAuth); $auth->save(); return $this->redirect(['index']); } } else { $group = $user->getGroup(); return $this->render('update', ['model' => $model, 'error' => $error, 'group' => $group]); } }