Welcome Guest, Not a member yet? Register   Sign In
How do I use $_GET data with CI's URLs?
#1

[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/...on/?page=2

Is that possible?

Your help is much appreciated
#2

[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.
#3

[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.
#4

[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?
#5

[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.
#6

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

[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.
#8

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

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

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

[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.




Theme © iAndrew 2016 - Forum software by © MyBB