当前位置:Gxlcms > PHP教程 > 分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目,该如何处理

分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目,该如何处理

时间:2021-07-01 10:21:17 帮助过:3人阅读

分享框架式网站系统的权限处理,尤其针对大型项目和二次开发项目


user表就是用户表了,可以存储上万条的用户也没关系,后面的groupid 为1 就是管理员权限,为2就是游客权限



model表存储框架的各个方法名,后面的group是set集合类型,代表哪个组拥有这个权限

废话不多说,看例子代码

PHP code
  1. <!--
  2. Code highlighting produced by Actipro CodeHighlighter (freeware)
  3. http://www.CodeHighlighter.com/
  4. --><!--?php
  5. class IndexAction extends YouYaX
  6. {
  7. public function index()
  8. {
  9. header("Content-type: text/html; charset=utf-8");
  10. //登陆的步骤省略
  11. $user="我是游客";
  12. //$user="我是管理员";
  13. $data=$this--->find("user","string","user='".$user."'");
  14. $group_tmp=$data["groupid"];
  15. $this->show($group_tmp);
  16. }
  17. public function show($group_tmp){
  18. $list=$this->find("model","string","func='show'");
  19. $sql="select * from model where func='show' and find_in_set(".$group_tmp.",".$list['group'].")";
  20. if(mysql_num_rows(mysql_query($sql))){
  21. echo "权限通过";
  22. //处理下面的内容
  23. }else{
  24. echo "没有权限";
  25. }
  26. }
  27. public function showAll($group_tmp){
  28. $list=$this->find("model","string","func='showAll'");
  29. $sql="select * from model where func='showAll' and find_in_set(".$group_tmp.",".$list['group'].")";
  30. if(mysql_num_rows(mysql_query($sql))){
  31. echo "权限通过";
  32. //处理下面的内容
  33. }else{
  34. echo "没有权限";
  35. }
  36. }
  37. }
  38. ?>




欢迎参考。。。

------解决方案--------------------
model表需要加上model名,不然无法区分不同model的同名方法

人气教程排行