Welcome Guest, Not a member yet? Register   Sign In
changing / rewriting the URI
#1

[eluser]Unknown[/eluser]
so I have my uri that brings up search results

http://www.mysite.com/info/listing

and it works fine now problems, the problem I am having is that I want the URI to be different ... I want to change / rewrite it to be more like

http://www.mystie.com/info/listing/searc...earchTerm3

Problem is, doing a redirect I loose my $_POST data, trying to append those to the view file name obviously doesn't work either... any suggestions on how to achieve this?
#2

[eluser]Rick Jolly[/eluser]
Something like this?
Code:
function listing($searchTerm1 = false, $searchTerm2 = false, $searchTerm3 = false)
{
   if (! empty($_POST))
   {
      $terms = '';

      if (! empty($_POST['searchTerm1']))
      {
         $terms .= '/' . urlencode($_POST['searchTerm1']);
      }
      if (! empty($_POST['searchTerm2']))
      {
         $terms .= '/' . urlencode($_POST['searchTerm2']);
      }
      if (! empty($_POST['searchTerm3']))
      {
         $terms .= '/' . urlencode($_POST['searchTerm3']);
      }
  
      $this->load->helper('url');
      redirect('info/listing' . $terms);
   }
   else
   {
      $searchTerm1 = (! empty($searchTerm1)) ? urldecode($searchTerm1) : false;
      $searchTerm2 = (! empty($searchTerm2)) ? urldecode($searchTerm2) : false;
      $searchTerm3 = (! empty($searchTerm3)) ? urldecode($searchTerm3) : false;

      // continue...
   }
}
#3

[eluser]Mirage[/eluser]
What I do is to stick the cleaned Post data into a session variable, and read it out in the redirected method and use the url parameters to communicate paging

Code:
function listing($page=0) {
    if($_SERVER['REQUEST_METHOD']=='POST') {
        // sanitize post data
        $listingParams = $this->sanitize_post_data();
        
        if ($listingParams) {
            $this->session->set_userdata('listingparams', listingParams);
            header("Location: {$_SERVER['PHP_SELF']}";
            exit();
        }
    }

    // handle GET requests
    $listingParams= $this->session->userdata('listingparams');

    // redirect to the form if nothing was stored

    // else do the search

    // show the results view
    
}

HTH,
-m




Theme © iAndrew 2016 - Forum software by © MyBB