CodeIgniter Forums
Multiple views. One function or many in the controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Multiple views. One function or many in the controller? (/thread-36571.html)



Multiple views. One function or many in the controller? - El Forum - 12-07-2010

[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


Multiple views. One function or many in the controller? - El Forum - 12-09-2010

[eluser]nuwanda[/eluser]
Have you looked at the user guide for validation?

Try the Codeigniter tutorials on Nettuts, they are essential in my opinion.

Take your time and learn the basics. Write some code that checks what has been returned from a form and go from there.