CodeIgniter Forums
method GET in search result - 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: method GET in search result (/showthread.php?tid=29783)



method GET in search result - El Forum - 04-21-2010

[eluser]davidino86[/eluser]
Hi everybody,

i'm coding a search function that at the form submit, send GET data like this:

Code:
mysite.com/search/result?from=annunci&search=depilazione

but i like this url

mysite.com/search/result/annunci/depilazione


there is a function or configuration or something in CI that makes this without a rewrite role?


method GET in search result - El Forum - 04-21-2010

[eluser]mddd[/eluser]
I have used two ways to do that.

1. Use Javascript to handle the form. Before submitting the form, you change the form's "action" attribute, using the form's values. Something like:
Code:
(html)
<form name="myform" action="" method="post">
(your input fields here)
</form>

(javascript)
function onformsubmit(myform)
{
myform.action = '/search/result/' + myform.from.value + '/' + myform.search.value + '';
return true;
}

2. Use a forwarding mechanism. You send the form (with POST). In CodeIgniter, you rewrite the address and forward to a new page. Something like:
Code:
$url = site_url('search','result',$this->input->post('from'),$this->input->post('search'));
header($url);



method GET in search result - El Forum - 04-21-2010

[eluser]davidino86[/eluser]
i think the second one is the best for my idea, beacause if i put in a robot.txt some urls like search/result/var1/var2 the robots can find a page and i think this is something good for google.

i don't know if i'm explain.


method GET in search result - El Forum - 04-21-2010

[eluser]davidino86[/eluser]
_YESSS!

it works fine with the your second solution but i change the code:

Code:
function index()
    {
        //$url = site_url('search','risultato',$this->input->post('from'),$this->input->post('search'));
        $url =  base_url().'search/risultato/'.$this->input->post('from').'/'.$this->input->post('search');
        redirect($url);
    }

    function risultato()
    {
        $data['query'] = $this->search->get_search_result($this->uri->segment(3), $this->uri->segment(4));
        $this->template->parse_view('content', 'inc/risultato_ricerca_view', $data);
        $this->template->render();
    }

'cause header didn't work and i change the url var in another way.is it correct?


method GET in search result - El Forum - 04-21-2010

[eluser]mddd[/eluser]
Oh, I'm sorry, I was too quick with the header. It should be : header('Location: ' . $url);
But redirect() is fine; that basically does the same thing and it even has some more possibilities.

Seems fine to me. I am glad it worked for you!