Welcome Guest, Not a member yet? Register   Sign In
Modules with query functionality?
#1

[eluser]Tom Vogt[/eluser]
My problem:

I have a (fairly large) number of modules that handle my app.

I have a (small) number of navigation and action pages to access those modules.

So, for example, I have one navigation page that lets me access module A, function 1, 2 and 5, module B.1, B.2, B.3 and C.2, C.3 while another action page gives me A.1, A.2, B.4, B.5, B.6 - note the overlap.

Finally, those actions are not always available. Depending on the user's status, access rights, and current location/action, etc. they may or may not be there. In most cases, I want to show them if they are not available, but "greyed out".


Now here's the problem:

How to code all this without duplicating the "can I do this right now" checks all the time? My dream would be a query functionality - that I can query my controllers to check and report which actions they a) supply and b) are available right now.

Is that even possible with CI?
#2

[eluser]gon[/eluser]
This is possible and not so difficult.

First, you need controllers to check ACL before executing an action. You could write a base controller that checks user rights at the constructor. For doing this, you should write a _remap($action) function that will be called always (see the controllers documentation for this).
This function can access controller name, action and params checking URI segments. Then access DB and check user permissions for controller / action.
All controllers extend will base, so ACL is checked automatically.
Obviously, there should be a module for changing permissions, roles, and so on. Design the after your needs.

Then you can write a helper, something like acl_anchor. You would pass a controller, action and params. The helper would check ACL for this controller / action (using the same library that the controller, DRY) and return a real anchor HTML, or just a greyed text span if the user doesn't have rights to execute that action.

Cheers.
#3

[eluser]Tom Vogt[/eluser]
Hm, that would be a start.

Let me elaborate a little. I'm talking about a web-based game here. So I have lots of user states (gold, skills, etc.) as well as lots of actions (easily a hundred).

I have "action controllers" that sort the available actions, because the total list would just be way too long. That's where my problem comes in. I'd just have to have encapsulated modules, e.g. when I add a new building that offers new actions, I'd love to have everything there, not have to add stuff here and over there as well.

So, one controller and one helper per module? But how can I do stuff like "load all helpers in this directory" ?




Theme © iAndrew 2016 - Forum software by © MyBB