1

我正在尝试根据用户访问级别显示或不显示链接。链接会有所不同,具体取决于用户可能所在的站点部分。链接也可能不都在一个菜单中。它们很可能出现在页面上的不同位置。

目前我有一个包含用户、组和部分的数据库表。主菜单是根据 Sections 数据库表构建的。我想我应该创建一个 Actions 表并添加一个我想为操作菜单中的每个部分显示的链接。所以,到目前为止我的桌子是这样的。

Users
user_id

Groups
group_id
group_title

Sections
section_id
section_title

我正在考虑添加的表。

Actions
action_id
action_title
action_group_id 
action_section_id

我不确定的部分是我是否应该为每个允许访问的组多次添加相同的链接到 Actions 表中。或者,只需添加一次并执行如果组 id 大于,则显示链接。

多次输入同一链接的示例。

action_id   action_title    action_group_id     action_section_id
1           View all        1                   1
2           View all        2                   1
3           View all        3                   1

我希望不要用一堆 if/then 语句淹没页面。另外,这似乎不是最好的处理方式,因为它需要人工解释访问级别代表什么。

对此的任何帮助表示赞赏。我可能会在这里完全错误的方向?

4

3 回答 3

2

使用附加表创建多对多关系,在该表中为组有权访问的每个权限插入一个条目。我是否正确假设部分是您正在创建的权限?

Table: Group_Section (Or whatever you'd like to name it)

Group_id | Section_ID
---------+-----------
       1 |         1
       1 |         2
       1 |         3
       2 |         1
       2 |         3
         |

您可以看到 ID = 1 的组可以访问部分 1,2,3,而 ID = 2 的组只能访问 1,3。然后,您可以将任何权限添加到您想要的表中,并通过使用外键来管理它们。

那有意义吗?

于 2012-11-16T22:06:03.730 回答
0

Here is a good article but the things are discussed in general http://en.wikipedia.org/wiki/Access_controlenter link description here

In your case, use what TheCapn wrote and I'll just add, that its 'best to start session for every user and just check his access level when he's trying to reach a restricted part.

于 2012-11-16T22:09:13.787 回答
0

Personnaly, to do this kind of thing, i set a user level in the user table and a section level in the section table. Then you simply have to filter the section according to your user level.

You can do this by adding a statemtn to you sql like

AND section_level >= "user_level";

or then again, get all the section and filter tham with php.

foreach($section as $s){
 if ($s->level >= user_level) echo $s->title
}

Of course, you'll need to adjust the <. = and > according to the hierachy of your system.

I personnaly use a lowering hierachy, meaning, the lower the level you are the more right you have. This way you can make a 'banned' user by setting his level to 99 or something.

THis would be only for your menus, make sure you control the user_level on each page as well so if someone get to the page directly it get kicked..

Hope it points your in the right direction. ;)

于 2012-11-16T22:09:41.687 回答