CodeIgniter Forums
better way of getting get/post vars then _GET and _POST - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: better way of getting get/post vars then _GET and _POST (/showthread.php?tid=26341)



better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]pocketmax[/eluser]
is there a better way of getting GET and POST vars then using the standard $_GET and $_POST? or is that the only way to get POST/GET vars in CI?


better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]WebsiteDuck[/eluser]
$this->input->get('variable');
$this->input->post('variable');

http://ellislab.com/codeigniter/user-guide/libraries/input.html


better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]pocketmax[/eluser]
Is there a way I can get a quick assoc array of the get or post vars? I tried $this->input->get() thinking it would automagicly give me the assoc but no such luck.


better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]Dyllon[/eluser]
[quote author="pocketmax" date="1263271571"]Is there a way I can get a quick assoc array of the get or post vars? I tried $this->input->get() thinking it would automagicly give me the assoc but no such luck.[/quote]

The get() and post() functions of the input class will fetch only one value at a time, if you need the assoc array then use $_GET or $_POST


better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]Colin Williams[/eluser]
It's a bit of a bizarre question that pops up here from time to time. It's akin to saying, I have this array:

Code:
$foo = array('name' => 'Sam', 'id' => '342');

Does CI provide a way to get $foo as an associative array?

(Note, if it's security you are worried about, you can xss_clean() the array before using it)

Code:
$values = xss_clean($_POST);



better way of getting get/post vars then _GET and _POST - El Forum - 01-11-2010

[eluser]Dyllon[/eluser]
In addition to what Colin said if you have global xss filtering on the input class is nice enough to automagically clean the $_POST array for you.