I currently have an array that hold information that a user can do. I currently use one instance of this in a dropdown menu which is very nice. What I want to do now is only include particular items if they have access to it. So say if $user_access=2 then they can do Download->small_image but not Download->large_image. I would like to be able to assign what the default access for each item in the array…even the key. So I can say a user access is 0 so they shouldn’t display “Download” at all.
I thought maybe putting the access integers for each in an object. So $access->download->small_image = 2; and then I could check one by one if an access level is greater than or equal to it and add it to the array? I’m actually not sure how I would do the loop and build up the array correctly. Another way…maybe put the access value in the actual array somehow? Any ideas would be great.
$var = array("Download" =>
array("small_image" => "ajax_load",
"large_image" => "/master.php"),
"Page" =>
array("Edit" => "edit.php",
"View" => "view.php",
"Stuff" => "stuff.php")
);
Access control is always a vague question, because there’s an unlimited amount of options. It sounds like you would be happy with an access array, IE:
I would probably use an array for your ACL (Access Control List) also:
Then call a function to authorize:
Sorry, hope that didn’t go off topic too much.
But you can adapt that to display your menu. I’m assuming you have a login system already of coarse 🙂
Edit:
So it works in the same principle, but all the information is centralized.
What I would do if I wasn’t using a database is store it as a json file.
You don’t want to hard code it into a php file, you want it easily modifiable.