PHP OOP architecture question (OOP against Roles) -


there users different privileges in system. privileges hierarchical

class user{//abstract user not logged in     //function signin(){} }  class guest extends user{  }  class fulluser extends guest{     static function signup(){}//create account     function signout(){} }  class moderator extends fulluser{           function edit(){}//some new method introduced here,never introduced before }  class admin extends moderator{            //can }  //can use fulluser::signup() 

is architecture good? can advice me else? wondering best way create user - write constructor? or let "factory" function.

function signin($username, $password) 

i'm new oop in php, accept wise advices, links, etc.


edit: i'm planning use role - checking system:

if(!method_exists($user->addcomment())) die('access denied') 

what think of it?


edit 2: should create role table role in axis x , method in axis y?

            comment | post |  editpost | kill guest          0        0        0         0 fulluser       1        0        0         0 moderator      1        1        1         0 admin          1        1        1         1 

and later should write this

function addcomment($user){ if(!$roles [$this->$role][__function__])return; .... } 

is better oop, wise programmers?

roles way go.

you can simple letting each user have public $role attribute $role number (e.g. 9 = admin, 6 = fulluser, 3 = guest).

the database table this

users id  username    password    role 1   admin       somepass    9 2   someuser    somepass    3 

in code stuff ´if ($user->role >= 9)´.

if want, can have role table instead of using numbers - this:

roles id  role 1   admin 2   fulluser 3   user 4   guest 

you make more advanced 1 user can have array of roles.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -