I’d like to impose that the user choose one entity from the database and then be stuck with it until explicitly released. The idea is to override any chance of any ability of any form to edit any other record for that model until it is explicitly released.
Picture it like this: user is logged in… gets record from database… app saves the id to the session. Any other actions from any and all controllers henceforth will use the id saved in session instead of anything in the url or otherwise. This entity serves as context for other entities, so when editing those other entities, only the ones associated with this one will be available, etc, etc. User opens a new tab hoping to access a different entity and can only access this one. When the user is done with this entity, the controller will call a special action, “done()” which takes the id out from session and now frees the user to select a different entity/context.
I started off doing this in the controller actions. But it’s getting repetitive and tiresome… and the controller logic is muddied by all this extraneous id management (making it even more fun, I’m giving the user the ability to create a new entity and then this new one is the one that gets locked in until released).
My first thought was to move it to the model. Then the controller does’t have to manage the id any more other than releasing it (the idea being that the controller will work with the id passed in the url the first time, but thereafter, will be locked in to that id until its released because the model will end up self-assigning the id after that initial get($id) ).
But then, realizing I want this to be a behavior at least one other model in my app follows, I thought I should make it a behavior.
Anyway. The session can’t be accessed from the model. So that kills that idea.
I briefly thought of moving it to beforeFilter() in AppController, but that has no access to model data.