Welcome Guest, Not a member yet? Register   Sign In
Multiple views. One function or many in the controller?
#1

[eluser]Unknown[/eluser]
I'm fairly new at this and I have a question about style. I have some logic that's basically like this:

Code:
If (user says no) then
    Display a view with a radio box asking for a reason.
                o  Not enough time
                o  too much money
                o  Already done this

Depending on feedback, if it's too much money. Display another view
                How much would you be willing to pay? _______

If the user didn't enter a numeric or didn't enter anything, ask again:
                How much would you be willing to pay? _______

THEN, In any case, store all the information provided.


To me it seems like this is all one logical unit, and my first thought was to create just one function that would get called on submit of both these views. But then my question is -- what is the right way to pass the context back and forth from the controller to the views?

The other way to do this would be to have a different submit function for each view, but this seems like the flow could get very complex very quickly. Even with this simple case you'd have 4 functions.

It seems like this is a fairly common thing to do but I haven't found an example, so any help is much appreciated.

R
#2

[eluser]Unknown[/eluser]
I read my post and maybe it's not clear. It's basically a very general question about moving data between the controller and the view.

doesn't make sense. You're right about the M, the V, and the C. It's just that if you think about it, the M and the V have to keep passing information back and forth in a kind of flow of logic. This is true for all form based logic. The idea that flow is no longer just straight down-the-page.

In the controller, call a view to display dialog box The view then displays a dialog box with a submit button. The user selects one. Now control goes back to the controller, but exactly how is this new context, i.e. the selected item of the dialog box, sent back to the controller?

You say "Ah, the form input tag says to call a function when you hit the submit button!" This is true. But what if I have context in the controller that was set up before I displayed the form? For example, let's say I found out the user's name, address, phone number, and just displayed the dialog to find out if they wanted to ship 2-day mail or not. I need all that prior information when I do the additional processing after I get their response.

You say "Ah, you can store that information in hidden fields, or in user_data or you can put that information on the URL and then pass it back to whatever function you call using the submit button!"

This is true. But I'm wondering what the best practice is. Which of the above to use first of us. Then, whether it makes sense to callback into the same function (i.e. the original function that does the original processing) and have some kind of "if" condition that tests for the state of things, whether the dialog box has been called and whether the user has entered a valid response. Or is it better to callback into new functions which obscures the flow of business logic and can get very cumbersome if there is more information to add (which may mean more views and more callbacks to new functions.)

R




Theme © iAndrew 2016 - Forum software by © MyBB