CodeIgniter Forums
How do I use $_GET data with CI's URLs? - 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: How do I use $_GET data with CI's URLs? (/showthread.php?tid=14461)

Pages: 1 2


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]KeyStroke[/eluser]
Hi there,

I'm having a lot of problems with CI's URL structure for passing data that may or may not appear in the URL, such as page numbers for example.

So I'm wondering if I could use both CI's URLs and pass $_GET data to them like this:

Quote:http://example.com/index.php/controller/function/?page=2

Is that possible?

Your help is much appreciated


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]Popcorn[/eluser]
$_GET data is destroyed by CodeIgniter so there is no way to gain access to it.

Quote:GET data is simply disallowed by CodeIgniter since the system utilizes URI segments rather than traditional URL query strings (unless you have the query string option enabled in your config file). The global GET array is unset by the Input class during system initialization.



How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]bitist[/eluser]
I'd read in a topic how can you allow this type of URL
/controller/method/param1/param2/?param3=xxx&param4=yyy

Use these settings in your config.php
Code:
$config['uri_protocol'] = "PATH_INFO";
$config['enable_query_strings'] = TRUE;

Maybe this helps.


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]KeyStroke[/eluser]
Thanks devpedia, it works great!

Are there any security or performance issues involved in enabling $_GET data in CI though?

Also, what does the "$config['uri_protocol'] = "PATH_INFO";" line mean?


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]garymardell[/eluser]
You will have to use $this->input->get('whatever');
I do believe as CI destroys the initial $_GET[].
I may be wrong but anyways there is no harm in using the input library.


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]Colin Williams[/eluser]
CI won't unset $_GET if $config['enable_query_strings'] == TRUE


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]meridimus[/eluser]
I think it's better to try not to use $_GET['var'];

Instead, using mod_rewrite you can access variables as part of the url e.g.

Quote:yoursite.com/blog/search_date/2009/1/6

would be —
Code:
class Blog extends Controller
{
     function search_date($year, $month, $day)
     {
          $data = array
          (
               "year" => $year, // would be 2009
               "month" => $month, // would be 1
               "day" => $day // would be 6
          );

          $this->load->view("view_search_date", $data);
     }
}

Much better way to do it.


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]KeyStroke[/eluser]
gazza: yea I'll use that

meridimus: but that's exactly what I'm trying to avoid. Smile


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]meridimus[/eluser]
Why are you trying to avoid it?


How do I use $_GET data with CI's URLs? - El Forum - 01-03-2009

[eluser]Colin Williams[/eluser]
The only time I've ever HAD to use $_GET is when writing a facebook app. The facebook requests to your server are query stringed.