Welcome Guest, Not a member yet? Register   Sign In
Pagination Problem
#1

[eluser]bcarter[/eluser]
Hi all

I have a bit of a problem which I have come up against. I have recently built a lead tracking application of sorts which was working fine. Anyway I've intergrated into another project and had a go at streamlining it which has gone pretty well except.....

...the pagination. I run a search and it works just right however when I click on the '2' on the pagination links I get a 404 error, page not found.

I have no idea why, can someone help me please?

Here's my controller
Code:
<?php

class Enquiry extends CI_Controller {

    function __construct()
    {
        parent::__construct();
        $this->load->library('ion_auth');
        $this->load->library('my_functions');
        $this->load->library('form_validation');
        if (!$this->ion_auth->logged_in())
        {
            //redirect them to the login page
            redirect('auth/login', 'refresh');
        }
    }
    
    function index()
    {
        //Load helpers, profiler, models etc
        $this->load->model('enquiries/Search_model');
        $this->output->enable_profiler(TRUE);
        $this->load->library('pagination');
        
        //Load up any data you need
        $data['page_title'] = 'Search Lead Database';
        
        //Form Validation
        $this->form_validation->set_rules('search', 'Search', 'trim|xss_clean');
        
        //Start to build the page
        $this->load->view('includes/head', $data);
        $this->load->view('enquiries/includes/header', $data);
        
        //And the rest
        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('enquiries/search_view', $data);//show errors here
            
        } else {
            
            $data['term'] = $this->input->post('search');
            $data['type'] = $this->input->post('type');
            $data['interest'] = $this->input->post('interest');
            $data['source'] = $this->input->post('source');
            $data['referer'] = $this->input->post('referer');
            $data['lead_status'] = $this->input->post('status');
                
            $data['total_rows'] = $this->Search_model->num_rows_search_results($data['term'],$data['type'], $data['interest'], $data['source'], $data['referer'], $data['lead_status'] );
    
            $config['base_url'] = base_url() . "index.php/enquiries/enquiry";
            $config['total_rows'] = $data['total_rows'];
            $config['per_page'] = 10;
            $config['num_links'] = 20;
            $config['first_link'] = 'First';
            $config['last_link'] = 'Last';
            $config['full_tag_open'] = '<div id="pagination">';
            $config['full_tag_close'] = '</div>';
            
            $this->pagination->initialize($config);
            
            $data['results'] = $this->Search_model->search_results($data['term'],$data['type'], $data['interest'], $data['source'], $data['referer'], $data['lead_status'], $config['per_page'], $this->uri->segment(3));
            
            $this->load->view('enquiries/search_results_view', $data);
        }
        
        $this->load->view('includes/footer');
        
    }
}

Now I'm assuming that because it works in the first instance there's no need to post the views or models here however, if I'm wrong (usually am) then I will post.

Please help me Obi Wan, you're my only hope!
#2

[eluser]marcogmonteiro[/eluser]
How are you passing the string the user are searching from one page to another? maybe you get the 404 because there's nothing to search on the second page... That happened to me in the past.
#3

[eluser]bcarter[/eluser]
I was just about to post the code for the form which sits in the page and uses the value = set_value() method, but then I realised that when you click the pagination link it doesn't submit the form so there are no $POST values!

Thanks for making me think!

Just out of interest would you assign the $POST values as session variables?
#4

[eluser]boltsabre[/eluser]
You could do that, or you could also tack the search post value onto your URL and access it using the URI helper.
#5

[eluser]marcogmonteiro[/eluser]
I probably wouldn't do that. Last time I put search values on URL I had a lot of problems. When people searched stuff with spaces or Latin characters. All stuff that you shouldn't use on CodeIngiter via url. So I would go and put that on a session variable.
#6

[eluser]boltsabre[/eluser]
That's a very fair point, I didn't really think my post through too well!
#7

[eluser]InsiteFX[/eluser]
He's getting the erorr because he is not setting the uri_segment!
Code:
// controller/method/etc - you may need to change this to the right segment number!
$config['uri_segment'] = 3;

InsiteFX
#8

[eluser]marcogmonteiro[/eluser]
But if he's using the 3rd segment he shouldn't have any problems with that. CodeIgniter uses the 3rd has default no?




Theme © iAndrew 2016 - Forum software by © MyBB