/** * Deletes an existing Role model. * If deletion is successful, the browser will be redirected to the 'index' page. * @param string $id * @return mixed */ public function actionDelete($id) { $item_name = $this->findModel($id); $f = \backend\models\AuthAssignment::findOne($id); if ($f != null) { $f->delete(); } $item_name->delete(); return $this->redirect(['user/index']); }
/** * Finds the AuthAssignment model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $item_name * @param string $user_id * @return AuthAssignment the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($item_name, $user_id) { if (($model = AuthAssignment::findOne(['item_name' => $item_name, 'user_id' => $user_id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Find the AuthAssighment model based on its user_id value * @param type $user_id * @return type * @throws NotFoundHttpException */ protected function findAuth($user_id) { if (($auth = AuthAssignment::findOne(['user_id' => $user_id])) !== null) { return $auth; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function update($runValidation = true, $attributeNames = NULL) { if (!empty($this->password)) { $this->password_hash = Yii::$app->security->generatePasswordHash($this->password); } $assignment = \backend\models\AuthAssignment::findOne(['user_id' => $this->id]); if ($assignment != null) { $assignment->item_name = $this->auth_item; if (!$assignment->update()) { print_r($assignment->getErrors()); exit; } } else { $this->save_assignment($this->id); } $this->status = $this->status == 1 ? 10 : 0; parent::update(); return true; }