/** * Lists all RoleAction models. * @paran int 上级节点id * @return mixed */ public function actionIndex($pid = 0) { if (!$this->is_access('roleaction/index')) { Yii::$app->session->setFlash('error', $this->errorInfo); return $this->redirect($this->redirectUrl); } $query = RoleAction::find(); $query = $query->andWhere(['parent_id' => $pid]); $dataProvider = new ActiveDataProvider(['query' => $query]); Yii::$app->view->params['meta_title'] = '角色权限节点'; return $this->render('index', ['dataProvider' => $dataProvider]); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = RoleAction::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'action_name', $this->action_name])->andFilterWhere(['like', 'controller_name', $this->controller_name])->andFilterWhere(['like', 'module_name', $this->module_name]); return $dataProvider; }
/** * @inheritdoc */ static function accessRule($controller = '', $action = '') { $userid = Yii::$app->user->id; $user = User::find()->select('user_type_id')->where(['id' => $userid])->one(); if ($user->user_type_id == 1) { return true; } $roleAction = RoleAction::find()->where(['action_name' => strtolower($action), 'controller_name' => strtolower($controller)])->one(); if (!empty($roleAction)) { $actionPermission = RoleMaster::find()->where(['role_action_id' => $roleAction->id, 'user_type_id' => $user->user_type_id])->one(); if (!empty($actionPermission)) { return true; } else { return false; } } else { return true; } }
use common\models\RoleController; /* @var $this yii\web\View */ /* @var $model common\models\RoleAction */ /* @var $form yii\widgets\ActiveForm */ $form = ActiveForm::begin(); ?> <div class="box-body"> <div class="form-group"> <?php echo $form->field($model, 'module_name')->dropDownList(ArrayHelper::map(RoleAction::find()->all(), 'module_name', 'module_name')); ?> </div> <div class="form-group"> <?php if ($model->isNewRecord) { echo $form->field($model, 'controller_name')->dropDownList(ArrayHelper::map(RoleAction::find()->all(), 'controller_name', 'controller_name')); } else { echo $form->field($model, 'controller_name')->textInput(['maxlength' => true, 'class' => 'form-control', 'readonly' => 'readonly']); } ?> </div> <div class="form-group"> <?php echo $form->field($model, 'action_name')->textInput(['maxlength' => true, 'class' => 'form-control']); ?> </div> </div> <div class="box-footer"> <?php echo Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => 'btn btn-primary']); ?>
public function getTreeModuleView($user_type_id = '') { $html_tree_view = ""; $m = 1; $c = 1; $a = 1; $roleModule = RoleAction::find()->select('module_name')->groupBy('module_name')->all(); if (!empty($roleModule)) { $html_tree_view .= '<div class="row">'; foreach ($roleModule as $key => $module) { $module_name = $module->module_name; $html_tree_view .= '<div class="col-md-12">'; $html_tree_view .= '<li id="module_' . $module_name . '">'; $html_tree_view .= '<input type="checkbox" id="' . $module_name . $m . '" class="module_group" name="RoleMaster[module][]" value="' . $module_name . '"/> '; $html_tree_view .= '<label for="' . $module_name . $m . '">' . ucfirst($module_name) . '</label>'; $roleController = RoleAction::find()->select('controller_name')->where(['module_name' => $module_name])->groupBy('controller_name')->all(); if (!empty($roleController)) { $html_tree_view .= '<ul>'; $html_tree_view .= '<div class="row">'; $ca = 1; foreach ($roleController as $key => $controller) { $controller_name = $controller->controller_name; if ($ca == 4) { $ca = 1; $html_tree_view .= '</div><div class="row"><div class="col-md-4">'; } else { $html_tree_view .= '<div class="col-md-4">'; } $html_tree_view .= '<li>'; $html_tree_view .= '<i class="icon-file"></i>'; $html_tree_view .= '<input id="' . $controller_name . $m . $c . '" type="checkbox" class="controller_group" ref="main_grp' . $controller_name . '" name="RoleMaster[controller][]" value="' . $controller_name . '"/> '; $html_tree_view .= '<label for="' . $controller_name . $m . $c . '">' . ucfirst($controller_name) . '</label>'; $roleAction = RoleAction::find()->select('id,action_name')->where(['controller_name' => $controller_name, 'module_name' => $module_name])->groupBy('action_name')->all(); if (!empty($roleAction)) { $html_tree_view .= '<ul>'; foreach ($roleAction as $key => $action) { $action_name = $action->action_name; $actionPermission = RoleMaster::find()->where(['role_action_id' => $action->id, 'user_type_id' => $user_type_id])->one(); $html_tree_view .= '<li>'; $html_tree_view .= '<i class="icon-file"></i>'; //if(empty($actionPermission)){echo 1; die;} $action_check = !empty($actionPermission) ? 'checked="checked"' : ''; $html_tree_view .= '<input id="' . $action_name . $m . $c . $a . '" type="checkbox" class="action_group" ref="main_grp' . $action_name . '" name="RoleMaster[action][]" value="' . $action->id . '" ' . $action_check . '/> '; $html_tree_view .= '<label for="' . $action_name . $m . $c . $a . '">' . ucfirst($action_name) . '</label>'; $html_tree_view .= '</li>'; $a++; } $html_tree_view .= '</ul>'; } $html_tree_view .= '</li>'; $html_tree_view .= '</div>'; $c++; $ca++; } $html_tree_view .= '</ul>'; } $html_tree_view .= '</li>'; $html_tree_view .= '</div>'; $m++; } } $html_tree_view .= '</div></div>'; return $html_tree_view; }