douyi5157 2013-08-23 17:44
浏览 112
已采纳

获取Joomla 2.5中的当前用户访问级别

In Joomla 2.5.14, I have a script that gets the current user group id, like:

$groups = $user->get('groups');
foreach($groups as $group) {
    echo "<p>Your group ID is:" . $group . "</p>";
};

Now, I need to count the number of articles this user is able to read, given his access level.

For that, I need to select the access level from the viewlevels table, that looks like this:

id     title            rules JSON encoded access control.
1   Public      [1]
2   AccessA     [13,8,16,17]
3   AccesssF    [8]
4   AccessD     [14,8]
6   AccessB     [8,16,17]
7       AccessC     [8,17]

So, for example, Group 17 may read the articles in AccessA, AccessB and Access C.

I tried the following query, but it isn't selecting any rows:

$query="SELECT * FROM xmb9d_viewlevels WHERE rules LIKE '%.$group.%'";

How can I select all the acess levels for the current user group and then count the number of articles he's able to read?

Thanks for helping!

  • 写回答

2条回答 默认 最新

  • duankange2433 2013-08-23 18:15
    关注

    I think you just need to remove the periods from within the LIKE clause. Such as:

    $query="SELECT * FROM xmb9d_viewlevels WHERE rules LIKE '%$group%'";
    

    Also, to make it not specific to the database you should substitute #__ (Note: it's two underscores) for the table prefix:

    $query="SELECT * FROM #__viewlevels WHERE rules LIKE '%$group%'";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了