/** * 返回access 里面name */ function access() { $model = Access::find()->all(); $t = \app\core\Arr::parentTree($model, $this->access_id); unset($s); foreach ($t as $v) { $s .= $v . "."; } return substr($s, 0, -1); }
static function get() { /** * 控制器中可设置当前启用的URL $this->active = array('system','i18n.site.index'); */ if (property_exists(\Yii::$app->controller, 'active')) { $active = \Yii::$app->controller->active; if (!is_array($active)) { $active = array($active); } if ($active) { foreach ($active as $v) { $v = str_replace('.', '/', $v); if (strpos($v, '.') !== false) { $ac[] = url($v); } else { $ac[] = $v; } } } $active = $ac; } $modules = cache_pre('all_modules'); if ($modules) { foreach ($modules as $k => $v) { $file = \Yii::$app->basePath . "/modules/{$k}/Menu.php"; if (file_exists($file)) { $cls = "app\\modules\\" . $k . "\\Menu"; $menus = $cls::add(); foreach ($menus as $key => $val) { if (!$menu[$key]) { unset($actived); if (Arr::array_in_array($key, $active)) { $actived = 'active'; } $menu[$key] = array('label' => __($key), 'url' => '#', 'options' => array('class' => "dropdown {$actived}"), 'template' => "<a href=\"{url}\" data-toggle='dropdown' class='dropdown-toggle'>{label}</a>"); } foreach ($val as $_k => $_u) { unset($actived); if (Arr::array_in_array($_u, $active)) { $actived = 'active'; } $menu[$key]['items'][] = array('label' => __($_k), 'url' => $_u, 'options' => array('class' => $actived)); } } } } } if (!\Yii::$app->user->isGuest) { $menu[] = array('label' => \Yii::$app->user->identity->username, 'url' => '#', 'itemOptions' => array('class' => 'dropdown'), 'template' => "<a href=\"{url}\" data-toggle='dropdown' class='dropdown-toggle'>{label}</a>", 'items' => array(array('label' => __('logout'), 'url' => array('auth/open/logout')))); } // dump($menu);exit; return $menu; }
function actionReturn($code) { $postdata = array('client_id' => $this->app_key, 'redirect_uri' => urlencode($this->url), 'client_secret' => $this->app_secret, 'code' => $_GET['code'], 'grant_type' => 'authorization_code'); $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => Arr::query($postdata))); $data = json_decode(Load::url(Taobao::url_access_token(), $opts)); $access_token = $data->access_token; if ($access_token) { try { $me['id'] = $data->taobao_user_id; $me['name'] = $data->taobao_user_nick; $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token); flash('success', __('login success')); $this->redirect(return_url()); } catch (OAuthException $e) { flash('error', __('login error')); $this->redirect(return_url()); } } exit; }
/** * 用户绑定到组 */ public function actionBind($id) { $id = (int) $id; $model = \app\modules\auth\models\User::find($id); foreach ($model->groups as $g) { $groups[] = $g->group_id; } $rows = Group::find()->all(); if ($rows) { $rows = Arr::model_tree($rows); } if ($_POST) { $group = $_POST['group']; //绑定用户到组 UserGroup::UserGroupSave($id, $group); flash('success', __('bin user group success') . " # " . $id); redirect(url('auth/group/bind', array('id' => $id))); } echo $this->render('bind', array('rows' => $rows, 'groups' => $groups, 'model' => $model, 'id' => $id, 'self' => $model->yourself)); }
/** * 用户组绑定权限 */ public function actionIndex($id) { $id = (int) $id; $model = \app\modules\auth\models\Group::find($id); foreach ($model->access as $g) { $access[] = $g->access_id; } $d = $this->_get_modules(); Access::generate($d); $rows = DB::all('auth_access', array('select' => "id,name,pid")); foreach ($rows as $v) { $out[$v['id']] = $v; } $rows = Arr::_tree_id($rows); if ($_POST) { $auth = $_POST['auth']; GroupAccess::saveAccess($id, $auth); flash('success', __('set access success')); redirect(url('auth/auth/index', array('id' => $id))); } echo $this->render('index', array('rows' => $rows, 'out' => $out, 'model' => $model, 'id' => $id, 'access' => $access)); }
/** * 显示 向上的树结构 */ function getGroup_tree() { if (0 == $this->pid) { return __('root'); } $data = static::find()->all(); $out = \app\core\Arr::parentTree($data, $this->pid); return implode("<br>", $out); }