0

我使用 Yii 框架中的权限来访问管理员访问好作品的权限。但问题是所有管理员都可以看到网站上的所有菜单选项。我该怎么做才能让经理只能看到可以访问的菜单

4

1 回答 1

1

为每个菜单选项制作项目。使用您要显示的角色为该菜单项设置权限。在您的主布局中(或您输出菜单的位置):

$role = Rights::getAssignedRoles(Yii::app() -> user -> Id);
            foreach ($role as $role)
                $role->name;
            if ($role->name == 'Manager' or Yii::app()->user->isSuperuser) {
                $this->widget('ext.cssmenu.CssMenu', array('items' => array(array('url' => array('/user/general/index'), 'label' => "General", 'visible' => Yii::app()->user->checkAccess('general')), array('url' => array('/data'), 'label' => "Data", 'visible' => Yii::app()->user->checkAccess('data')), array('url' => Yii::app()->getModule('user')->clientsUrl, 'label' => "Clients", 'visible' => Yii::app()->user->checkAccess('clients')), array('url' => Yii::app()->getModule('user')->providersUrl, 'label' => "Data Providers", 'visible' => Yii::app()->user->checkAccess('providers')), array('url' => Yii::app()->getModule('user')->ordersUrl, 'label' => "Orders", 'visible' => Yii::app()->user->checkAccess('orders')), array('url' => Yii::app()->getModule('user')->profileUrl, 'label' => "Tools", 'visible' => Yii::app()->user->checkAccess('tools')), array('url' => Yii::app()->getModule('user')->logoutUrl, 'label' => Yii::app()->getModule('user')->t("Logout"), 'visible' => !Yii::app()->user->isGuest)),));
            } elseif ($role->name == 'Client') {
                $this->widget('ext.cssmenu.CssMenu', array('items' => array(array('url' => array('/user/general/index'), 'label' => "General", 'visible' => Yii::app()->user->checkAccess('general')), array('url' => array('/user/data'), 'label' => "Data", 'visible' => Yii::app()->user->checkAccess('data')), array('url' => array('/user/client/lists'), 'label' => 'Lists', 'visible' => Yii::app()->user->checkAccess('User.Client.Lists')), array('url' => array('/user/orders/index', "id" => Yii::app()->user->Id), 'label' => 'Orders', 'visible' => Yii::app()->user->checkaccess('User.Orders.Index')), array('url' => Yii::app()->getModule('user')->profileUrl, 'label' => "Profile", 'visible' => Yii::app()->user->checkAccess('tools')), array('url' => Yii::app()->getModule('user')->logoutUrl, 'label' => Yii::app()->getModule('user')->t("Logout"), 'visible' => !Yii::app()->user->isGuest))));
            }
            elseif ($role->name == 'Provider') {
                $this->widget('ext.cssmenu.CssMenu', array('items' => array(array('url' => array('/user/general/index'), 'label' => "General", 'visible' => Yii::app()->user->checkAccess('general')), array('url' => array('/user/data'), 'label' => "Data", 'visible' => Yii::app()->user->checkAccess('data')), array('url' => array('/user/provider/data', "id" => Yii::app()->user->Id), 'label' => 'Data', 'visible' => Yii::app()->user->checkAccess('User.Feeds.Feeds')), array('url' => array('/user/feeds/feeds', "id" => Yii::app()->user->Id), 'label' => 'Feeds', 'visible' => Yii::app()->user->checkAccess('User.Feeds.Feeds')), array('url' => array('/user/payments', "id" => Yii::app()->user->Id), 'label' => 'Payments', 'visible' => Yii::app()->user->checkAccess('User.Feeds.Feeds')), array('url' => Yii::app()->getModule('user')->logoutUrl, 'label' => Yii::app()->getModule('user')->t("Logout"), 'visible' => !Yii::app()->user->isGuest))));
            }

只是一个例子,很抱歉长字符串。

于 2013-08-05T11:07:23.870 回答