CodeIgniter Forums

Full Version: search with pagination: POST first, then GET?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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

I might change it to
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
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,

This is the method in my controller

function search()
       $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'));
        $fields['for'] = 'for';
        $fields['location'] = 'location';
        $rules['for'] = 'required';
        $data['page'] = 'search';
        $data['header'] = $this->load->view('includes/header', $data, true);

    // 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();
    // 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);


El Forum

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:

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