1,ThinkPHP安装
2,ThinkPHP之RBAC
一,建表:
user表 用户表
role表
1 user1 4
2 user1 6
module表 - 模块表 - Index模块
1 Index
action表
1, index Index
2,delete Index
3,add Index
二,创建_initialize方法,所有方法开始之前都通过他,这个时候判断权限
class AclAction extends Action(){
public function _initialize(){
$m = MODULE_NAME;//获取模块名字
$a = ACTION_NAME;
$USER_ID = $_SESSION['user_id'];
$model = M();
$sql = "select * from role,module,action where role.user_id={$user_id} and role.action_id = action.id and action.module_id = module.id and module.name='{$m}' and action.name = '{$a}'";
$rows = $model->query($sql);
if(!$rows){
$this->error('无权操作',U('Login/index'));
}
}
}
三,操作
获取get或者post操作 :$paiweiid = input('param.id');
ajax里面发送方法,不支持的时候,先全局申请一个变量
<script type="text/javascript">
var ajaxUrl = "{:url('paiwei/deck/add')}";
</script>
然后使用ajax方法则可以:
$.ajax(
{
type: 'post',
dataType: "json",
async:true,
url: ajaxUrl,
//url: "http://localhost/shifang/hisiphp/paiwei/deck/list",
data: {changsheng: changsheng},
success: function(data){
alert(data);
}
});