Welcome Guest, Not a member yet? Register   Sign In
passing variable through model

i'm stumped on this. couldn't find anything the documentation...
i have a view where i have a list of user profiles, each one has a userid in the url which you can click to see their full profile.

i have a controller (controller 1) that loads a model (model 1) to get a list of users then loads a view to display the list. each user is linked to a page (controller 2) that loads a model (model 2) and a detailed view of their profile. on the detailed view, i submit a form to a controller (controller 3) that loads a model (model 3) where i update their profile in the db.

how can i pass the user id from model 3 back to controller 2. controller 3 redirects to controller 2 when it's done.

this may be a stupid way of doing it. i'm open to better. but, what i'd really like to know is how to pass it back without dealing with cookies or sessions.

sorry if that's vague. any help would be greatly appreciated. my chops are dull.


I would recommend you to set up only one controller and
then having only one function/method for
- display user list
- display detailed infos for one user
- form submittion

Same with you modell: set up one model with needed functions
- get basic user list from db
- get detailed infos for user x
- update user x

All functions are pretty much related and there is no need
to build that many controllers and models for that.

I second @mawi27 here. You must have the user_id in Controller3, right?

So, there's not really any Controller conventions set in stone. However, most folks like to organize related operations in a single Controller. Again, it's okay to have 3 different Controllers all dealing with users, just a little strange I suppose. The only suggestion I'm trying to make here is that you might be making your code a bit difficult to manage unnecessarily.

EDIT. I See @luckyfella73 beat me to the punch in much clearer terms. ;-)

it was late and wasn't thinking clearly. i have one controller for users, but 3 functions.

the issue i had before was post vars vs. url segments, but i used session there, because it was appropriate.

what @mawi27 said will completely work. not used the the mvc and i felt like i needed the model to pass back to the controller what i see now it obviously has...

thanks everyone for all your help

Theme © iAndrew 2016 - Forum software by © MyBB