user表就是用户表了,可以存储上万条的用户也没关系,后面的groupid 为1 就是管理员权限,为2就是游客权限model表存储框架的各个方法名,后面的group是set集合类型,代表哪个组拥有这个权限废话不多说,看例子代码<?php
class IndexAction extends YouYaX
{
public function index()
{
header("Content-type: text/html; charset=utf-8");
//登陆的步骤省略
$user="我是游客";
//$user="我是管理员";
$data=$this->find("user","string","user='".$user."'");
$group_tmp=$data["groupid"];
$this->show($group_tmp);
  }
  public function show($group_tmp){
  $list=$this->find("model","string","func='show'");
      $sql="select * from model where func='show' and find_in_set(".$group_tmp.",".$list['group'].")"; 
      if(mysql_num_rows(mysql_query($sql))){
       echo "权限通过";
       //处理下面的内容
      }else{
       echo "没有权限";
      }
  }
  public function showAll($group_tmp){
      $list=$this->find("model","string","func='showAll'");
      $sql="select * from model where func='showAll' and find_in_set(".$group_tmp.",".$list['group'].")"; 
       if(mysql_num_rows(mysql_query($sql))){
       echo "权限通过";
       //处理下面的内容
      }else{
       echo "没有权限";
      }
  }
}
?>欢迎参考

解决方案 »

  1.   

    有的人会不以为然,它的妙处就在于你想要使某个用户拥有管理员权限,只要更改user表的groupid字段,同样道理,如果要使某个人或某个用户组无法访问某个方法,也只要改动model表即可用户组可以设置很多。。以上只举2个用户组例子
      

  2.   

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

  3.   


    同名方法 我表示没考虑过而且不大确定会不会报错我在控制器中写方法名  Add  都会和内置函数 add有冲突。。而且php中不大可能有什么同名函数的,一般都是function(param1='',param2='',param3='')是这种类型,所以我很肯定的说php函数没有同名函数