Welcome Guest, Not a member yet? Register   Sign In
how to use model?
#7

[eluser]Frank Berger[/eluser]
[quote author="crumpet" date="1223896000"]frank maybe you can answer a question for me too..
I am writing a function to display a view of a product right now. In the controller i have code to determine what privileges the user has to that product so it can decide what to display. Should this be in the model? My instinct was to put it there however then it makes my database calls less efficient, becuase I have already fetched the information about the product and stored it in a variable $product. I can do tests like $this->session->userdata('USER_ID') == $product['author']. If i make a model function called getUserAccess() or something then it will have to make an extra query to get information I have already queried... hope this makes sense[/quote]

makes sense to me, and I myself stand before similar situations quite often.

The thing is, permissions are either tied to the data-access model (for example that it incorporates the user-id when querying and not returning the dataset at all if no match - meaning access/read/write permissions ON the dataset) or they are tied to actions, which are in the view/controller domain.

So, if the question is if you should display lets say an 'edit' button, then it is definitely view/controller, as those two are responsible for drawing an edit-button or not. If it is a question of low-level access or read/write permissions, I would tend towards implementing it in the model, but carefully so that the model doesn't need to use or know how the user-name/id got there (means, the model should not access the session, the controller should access the session and pass the user-id/name to the model, which then either creates a private user object or uses the passed value directly.)

I am one of the many who posted an acl implementation (in my case for the controller) here, which I plan to extend to models too, but which is at this point not really production material.

Hope this makes sense to you, if not ask again. and of course this is highly imho and in my expirience Wink

Frank


Messages In This Thread
how to use model? - by El Forum - 10-12-2008, 09:14 PM
how to use model? - by El Forum - 10-12-2008, 10:41 PM
how to use model? - by El Forum - 10-12-2008, 10:55 PM
how to use model? - by El Forum - 10-12-2008, 11:42 PM
how to use model? - by El Forum - 10-12-2008, 11:54 PM
how to use model? - by El Forum - 10-13-2008, 12:06 AM
how to use model? - by El Forum - 10-13-2008, 12:51 AM
how to use model? - by El Forum - 10-13-2008, 01:05 AM
how to use model? - by El Forum - 10-13-2008, 01:20 AM
how to use model? - by El Forum - 10-13-2008, 01:28 AM
how to use model? - by El Forum - 10-13-2008, 02:10 AM
how to use model? - by El Forum - 10-13-2008, 02:43 AM
how to use model? - by El Forum - 10-13-2008, 02:53 AM
how to use model? - by El Forum - 10-13-2008, 02:59 AM
how to use model? - by El Forum - 10-13-2008, 03:04 AM
how to use model? - by El Forum - 10-13-2008, 03:08 AM
how to use model? - by El Forum - 10-13-2008, 03:17 AM
how to use model? - by El Forum - 10-13-2008, 03:34 AM
how to use model? - by El Forum - 10-13-2008, 03:43 AM
how to use model? - by El Forum - 10-13-2008, 03:49 AM
how to use model? - by El Forum - 10-13-2008, 03:54 AM
how to use model? - by El Forum - 10-13-2008, 03:55 AM
how to use model? - by El Forum - 10-13-2008, 03:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB