Assignment details on each Controller and Action for user


Hi !! everyone , I’m really have project about MVC . My example instance each controller is a class  and that class contains many action method . Now i want decentralization for user run on each controller and each action conjunction with database.

User have highest administrator is admmin, this user can create the group, delete, update on module admin access. Then i will show how to do it.

The first time we create table user vs table role is used to store list of names and powers.

--
-- Table structure for table `user`
--

CREATE TABLE IF NOT EXISTS `user` (
 `user_id` int(11) NOT NULL AUTO_INCREMENT,
 `user_name` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
 `user_pass` text COLLATE utf8_unicode_ci NOT NULL,
 `user_role` int(11) NOT NULL,
 PRIMARY KEY (`user_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

--
-- Table structure for table `role`
--

CREATE TABLE IF NOT EXISTS `role` (
 `role_id` int(11) NOT NULL AUTO_INCREMENT,
 `role_name` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `role_status` int(1) NOT NULL COMMENT '1:active | 0:inactive',
 PRIMARY KEY (`role_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

Then we create permissions table it used to hold the controller which users access.

--
-- Table structure for table `permissions`
--

CREATE TABLE IF NOT EXISTS `permissions` (
 `permissions_id` int(11) NOT NULL AUTO_INCREMENT,
 `permissions_code` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `permissons_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
 `permissions_status` int(1) NOT NULL DEFAULT '1' COMMENT '1:active | 0:inactive',
 `permissions_order` int(11) NOT NULL,
 PRIMARY KEY (`permissions_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

Final is create role_perms table to get powers of user for each role can do.

--
-- Table structure for table `role_perms`
--

CREATE TABLE IF NOT EXISTS `role_perms` (
 `role_perms_id` int(11) NOT NULL AUTO_INCREMENT,
 `role_id` int(11) NOT NULL,
 `permission_id` int(11) NOT NULL,
 `role_perms_value` text COLLATE utf8_unicode_ci NOT NULL COMMENT '1:ALL | 2:View | 3:Add | 4:Edit | 5:Delete',
 PRIMARY KEY (`role_perms_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;

My Example :

db1

 

db2

 

I hope the article is useful.

Bài viết mình viết bằng tiếng anh =]], nhưng các bạn có thể dùng google dịch translate củng có thể hiểu rỏ…Vì English is limit =]]….chúc các bạn có bài viết hữu ích, ai không hiểu hay có ý kiến mới thì cho mình tham khảo luôn nha bài viết .

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: