/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new ActionsUsers('create'); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['ActionsUsers'])) { $model->attributes = $_POST['ActionsUsers']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'actions' => $this->listActionsCanAccess)); }
public function addUserRoles($post, $user_id = NULL) { try { $allow_actions = $deny_actions = array(); foreach ($post as $key => $value) { if ($value == 'allow') { $allow_actions[] = $key; } if ($value == 'deny') { $deny_actions[] = $key; } } $allow_actions = implode(',', $allow_actions); $deny_actions = implode(',', $deny_actions); if ($user_id == NULL) { die('Dec 19, 2014 yêu cầu không hợp lệ - by ANH DUNG'); $roles = Yii::app()->session['roles']; $user_id = Users::model()->find("username like '{$roles}'")->id; } $allow_actionsRole = ActionsUsers::model()->find('controller_id = ' . $this->id . ' and user_id = ' . $user_id . ' and can_access like "allow"'); $deny_actionsRole = ActionsUsers::model()->find('controller_id = ' . $this->id . ' and user_id = ' . $user_id . ' and can_access like "deny"'); if ($allow_actionsRole) { $allow_actionsRole->actions = $allow_actions; } else { $allow_actionsRole = new ActionsUsers(); $allow_actionsRole->user_id = $user_id; $allow_actionsRole->controller_id = $this->id; $allow_actionsRole->can_access = 'allow'; $allow_actionsRole->actions = $allow_actions; } if ($deny_actionsRole) { $deny_actionsRole->actions = $deny_actions; } else { $deny_actionsRole = new ActionsUsers(); $deny_actionsRole->user_id = $user_id; $deny_actionsRole->controller_id = $this->id; $deny_actionsRole->can_access = 'deny'; $deny_actionsRole->actions = $deny_actions; } $allow_actionsRole->save(); $deny_actionsRole->save(); } catch (Exception $e) { Yii::log("Exception " . print_r($e, true), 'error'); throw new CHttpException("Exception " . print_r($e, true)); } }