CodeIgniter Forums
Passing $Data to the Controller from View? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Passing $Data to the Controller from View? (/showthread.php?tid=33314)



Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]thesocialhacker[/eluser]
Let's say i want to pass some data from the view back to the controller.
how is this done, in the CodeIgniter way?


Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]thesocialhacker[/eluser]
any other ways except uri-segment(3)?
i'd rather not have this exploitable by user?


Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]mddd[/eluser]
You shouldn't think of "sending from Controller to View". You probably mean sending information while requesting a new web page.
You could do this through the url (www.example.com/controller/method/argument) or using a form to POST information to the page.
In both occasions, there is no certainty of what a user can send. You must always check if the user's input is safe to use.


Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]natefons[/eluser]
the safest way i can think of, would be to pass it in a hidden POST.


Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]basementDUDE[/eluser]
if you just a need a product ID(small data) number, pass it thought URI.
if you need a comments(large data) from user then you have to make a forum in the view and post it to the controller.


Passing $Data to the Controller from View? - El Forum - 08-22-2010

[eluser]InsiteFX[/eluser]
There is a third parameter to the view!

Code:
Returning views as data
There is a third optional parameter lets you change the behavior of the function
so that it returns data as a string rather than sending it to your browser.
This can be useful if you want to process the data in some way. If you set the
parameter to true (boolean) it will return data. The default behavior is false,
which sends it to your browser. Remember to assign it to a variable if you want
the data returned:

$string = $this->load->view('myfile', '', true);

InsiteFX