Welcome Guest, Not a member yet? Register   Sign In
overall code organization: helper, library, core, or model?
#8

(01-02-2015, 11:30 PM)bclinton Wrote: It may be personal preference, but I think #3 is a model.  I try to do as little as possible in my controllers: validate the request, get info from a model, send it to the browser. I'd want something like this in my controller for #3:

$user = usermodel->get($id);   // or get it from the session or auth lib
$view = pagemodel->getOptimal($user);
I definitely agree it should work something like this. I tend to think of the controllers as switchboard operators and the models as the entity one is calling with whom to talk business.

(01-02-2015, 11:30 PM)bclinton Wrote: For #7, it really depends on how you are doing authentication.  I like to do it in a controller constructor hook, some might do it in a MY_Controller that they extend, or you could write a custom validation rule.  You could add a hasBidAccess function to your authentication library that calls a function in a datamodel that does a query.   There are a lot of options.
 
I'm sort of torn here. It certainly seems clear that a given page view or action should be intercepted by a controller if a user is not sufficiently privileged. Viewing admin dashboard, for instance, should not be accessible except by admin. On the other hand, other actions may depend on a lot of conditions that seem squarely in the Model camp: existence of records in a particular database, values from a database, etc. The rules for access to a particular action could be quite elaborate. I've heard discussion of using Interceptor Pattern in this context, but can't yet formulate a proper vision of code and data structures. In particular, creating three base controller classes:
* Public - for pages accessible to everyone
* User - for pages accessible to registered users
* Admin - for pages only accessible to Admins.
This might work fine for a simple site but what if you want to specify a-la-carte permissions like an ACL or *nix-style file permissions? Or what if you have N user levels rather than just these 3? I'd appreciate any thoughts on code structures, data structures, and code organization if anyone has any.
Reply


Messages In This Thread
RE: overall code organization: helper, library, core, or model? - by sneakyimp - 01-05-2015, 06:01 PM



Theme © iAndrew 2016 - Forum software by © MyBB