CodeIgniter Forums
GET Method, Query string with Clean url - 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: GET Method, Query string with Clean url (/thread-33573.html)



GET Method, Query string with Clean url - El Forum - 08-31-2010

[eluser]TheIgniter[/eluser]
Hi there,

I have a litle problem and i hope that someone will help me :

Suppose we have a function taht can filter data with 2 parameter .. I want to send some value to this function with the get method .. so i have :
Code:
<form method="get" action="<?php echo base_url() . 'mycontroller/myfunction/filter_by/'?>">
<select id="filter">
  <option value="">Selectionnez votre rĂ©gion </option>
  <option value="pays1">france</option>
  <option value="pays2">canada</option>
</select>
&lt;input  type="submit"/&gt; &lt;/form&gt;

When i submit, the url become :

Code:
mysite.com/mycontroller/myfunction/filter_by/?pays1=france&pays2=canada

So my question is how can i get this :
Code:
mysite.com/mycontroller/myfunction/filter_by/france/canada

I did some search but not enougth to undertund how to..
THanks in advance!!


GET Method, Query string with Clean url - El Forum - 08-31-2010

[eluser]CI_avatar[/eluser]
During on click of the submit button the default link will be generated above like
Code:
(mysite.com/mycontroller/myfunction/filter_by/?pays1=france&pays2=canada)
there no way we can do that.

But you may route the link
Code:
mysite.com/mycontroller/myfunction/filter_by/?pays1=france&pays2=canada
to
Code:
mysite.com/mycontroller/myfunction/filter_by/france/canada

Make a controller that will receives the get request then route it to the destination controller with rewritten URL

getcontroller.php
Code:
//code somewhat like this
header('Location: mysite.com/myfunction/filter_by/'.$this->input->get('pays1').'/'.$this->input->get('pays2'));

//please do some URL handling and manipulation to get the correct URL



GET Method, Query string with Clean url - El Forum - 08-31-2010

[eluser]pbreit[/eluser]
Will "$this->input->get" work there? Isn't the whole problem that querystrings don't work in CodeIgniter?

As outlined in this thread:
http://ellislab.com/forums/viewthread/159382

A very small bit of code will enable you to process a querystring as usual. Then you don't have to go through the idiocy of converting a proper querystring into URI parts.

Code:
class MY_Input extends CI_Input
{
    function _sanitize_globals()
    {
        $this->allow_get_array = TRUE;
        parent::_sanitize_globals();
    }
}



GET Method, Query string with Clean url - El Forum - 08-31-2010

[eluser]TheIgniter[/eluser]
[quote author="CI_avatar" date="1283321068"]During on click of the submit button the default link will be generated above like
Code:
(mysite.com/mycontroller/myfunction/filter_by/?pays1=france&pays2=canada)
there no way we can do that.

But you may route the link
Code:
mysite.com/mycontroller/myfunction/filter_by/?pays1=france&pays2=canada
to
Code:
mysite.com/mycontroller/myfunction/filter_by/france/canada

Make a controller that will receives the get request then route it to the destination controller with rewritten URL

getcontroller.php
Code:
//code somewhat like this
header('Location: mysite.com/myfunction/filter_by/'.$this->input->get('pays1').'/'.$this->input->get('pays2'));

//please do some URL handling and manipulation to get the correct URL
[/quote]

Thanks to both of u.. So, i will stick with your suggestion ..