Welcome Guest, Not a member yet? Register   Sign In
search with pagination: POST first, then GET?
#1

[eluser]Unknown[/eluser]
First of all, thanks to all the contributors to this forum
I've found it invaluable in my first CI project!

Ok, so I have a search page with pagination running fine

http://www.mysite.com/jobs/search/css:html/london
http://www.mysite.com/jobs/search/css:html/london/4
etc;

I might change it to
http://www.mysite.com/jobs/search/for/cs...n/offset/4
and then use $this->uri->uri_to_assoc(n)
if it helps my problem below.

But what I'm not sure about is when I want to call this URL
from a simple search form on the same page.

Should I use a GET method on the form and then try and turn
http://www.mysite.com/jobs/search?for=cs...n&offset=4
into
http://www.mysite.com/jobs/search/for/cs...n/offset/4
using htaccess or the routing feature of CI?

or should I use
some logic in the controller to check if it was a POST or GET
it's further comlicated because I would like to use the validation library to check if the fields are empty.

Any advice greatly appreciated,
Thanks.


This is the method in my controller

Code:
function search()
   {
    $this->output->enable_profiler(TRUE);
  
       $segs = $this->uri->segment_array();
    $search_txt = $this->uri->segment(3, 'all');
    $search_terms = explode(":",$this->uri->segment(3));    
    $search_location = $this->uri->segment(4, 'any');
    $search_offset = $this->uri->segment(5, 0);
    
    
        $this->load->helper(array('form', 'url'));
        $this->load->library('validation');
        
        $fields['for'] = 'for';
        $fields['location'] = 'location';
        $this->validation->set_fields($fields);
        
        $rules['for'] = 'required';
        $this->validation->set_rules($rules);
        
        $data['page'] = 'search';
        $data['header'] = $this->load->view('includes/header', $data, true);

    // pagination
    $this->load->library('pagination');
    $config['base_url'] = base_url().$this->uri->slash_segment(1, 'leading').$this->uri->slash_segment(2, 'both').$search_txt.'/'.$search_location.'/'; // cahnge to url
    $config['total_rows'] = $this->db->count_all('jobs');
    $config['per_page'] = '2';
    $config['full_tag_open'] = '<p>';
    $config['full_tag_close'] = '</p>';
    $config['num_links'] = 2;
    $config['uri_segment'] = $this->uri->total_segments();
    $this->pagination->initialize($config);
    // load jobs model
    $this->load->model('jobs_model', '', TRUE);
    $data['results'] = $this->jobs_model->get_jobs($search_terms,$config['per_page'],$search_offset);
    
    $data['pagination'] = $this->pagination->create_links();
    $this->load->view('search', $data);

  }
#2

[eluser]gon[/eluser]
One thing I wouldn't do is using validation for checking if URL fields are empty.
URI segments are also passed to the action function.
And you can check if they're empty this way:

Code:
function search($arg1 = null, $arg2 = null, $arg3 = null) {
  
   if (is_null($arg1) || is_null($arg2)) {

   }
....
....
....




Theme © iAndrew 2016 - Forum software by © MyBB