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 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line