Best place for user data
Posted: Mon Mar 23, 2009 1:08 pm
With many web applications you're dealing with users who log in and then do something with their account and their data.
Persisting the user can be done by use of a session. But I have been wondering what the best way is to convey that user id into the rest of the app. I have a MVC setup with Frontcontroller, controllers with actions, models, views and templates.
To give an example. You have the user_id in the session after he's logged in. Now he's going to insert a new item. The model for that item needs that user_id. Now does the controller get the user_id from the session, put it inside the data array that is being posted with the form and then all that data goes to the model to be validated and inserted?
Or does the controller put the user_id inside the form even before it's being posted (as a hidden input field)?
Or does the model itself ask the Authenticator (or however it's called) for the user_id? (and in case if it's not there, throw an exception)
Persisting the user can be done by use of a session. But I have been wondering what the best way is to convey that user id into the rest of the app. I have a MVC setup with Frontcontroller, controllers with actions, models, views and templates.
To give an example. You have the user_id in the session after he's logged in. Now he's going to insert a new item. The model for that item needs that user_id. Now does the controller get the user_id from the session, put it inside the data array that is being posted with the form and then all that data goes to the model to be validated and inserted?
Or does the controller put the user_id inside the form even before it's being posted (as a hidden input field)?
Or does the model itself ask the Authenticator (or however it's called) for the user_id? (and in case if it's not there, throw an exception)