How to divide multiple users access and permissions? i did it first time by creating different dashboard for 3 type users for example administrators redirected to user/admin/dashboard
and moderators to user/moderator/dashboard
and and so on. but i want to find an easy way to do this by knowing user roles and manage their access. my user table is something looks likes : mysql:
CREATE TABLE IF NOT EXISTS `users` (
`user_id` int(9) NOT NULL AUTO_INCREMENT,
`email_add` varchar(35) COLLATE utf8_bin DEFAULT NULL,
`password` varchar(128) COLLATE utf8_bin NOT NULL,
`last_login` datetime NOT NULL,
`usr_typ_id` int(4) DEFAULT NULL,
`permissions` varchar(50) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`user_id`),
UNIQUE KEY `email_add` (`email_add`),
KEY `fk_usr_typ_id` (`usr_typ_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=92090005 ;
-
ALTER TABLE `users`
ADD CONSTRAINT `fk_usr_typ_id` FOREIGN KEY (`usr_typ_id`) REFERENCES `user_type` (`type_id`);
Once i used drupal it was perfect, i wish just something look likes that,nothing completely like that.:)
Use the Permission Class.
Watch this video to see this in action.
I usually use a separated table to define user acces. Let's say its name is tbl_acces and it has 2 columns: usr_typ_id & menu_id.
A menu_id is can be a page or a function in the controllers. So if user access a function in controller via URL it will do some checking whether user is authorized to access that page/menu.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.