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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大