당신은 그것을 조작 할 수 있기 때문에 양식에 숨겨진 (GROUP_ID) 필드를 허용하지 않습니다.
단순히 group_id의 기본값을 설정하고 관리를 통해 변경하십시오.
기본 아이디어/구현 :
이
`gid` smallint unsigned not null default 0, //or members default value
사용자 테이블에 추가 -
alter table `users` add index(`gid`);
alter table `users` foreign key(`gid`) references groups(`id`) on delete restrict on update restrict;
- 현재 권한 열을 정상화하고 다중 선택을 할 수
create table `groups`(
id smallint unsigned not null auto_increment primary key,
`name` varchar(20) not null,
`permissions` varchar(255) not null, //JSON object '["read", "edit", "delete", "admin", "super"]'
created_at datetime
)engine=innodb;//or whatever engine you like
- 내 머리 위로 떨어져
class MY_Controller extends CI_Controller{
protected $_user;
protected $_permissions=array();
protected $_group;
public function __construct()
{
parent::__construct();
//check for a user logged in
$this->_user = ($user) ? $user : NULL;
//if user, get group and permissions
if($this->_user !== NULL)
{
$this->_get_group();
$this->_get_permissions();
}
}
public function _get_group(){
return $this->_group = $this->_user->group->name; //need to work this bit out
}
public function _get_permissions(){
return $this->_permissions = json_decode($this->_user->permissions, TRUE);
}
public function can_read(){
return in_array('read', $this->_permissions);
}
/// and so on etc
}