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

[eluser]codelearn[/eluser]
Hey guys,

Having slight trouble with the pagination class. Getting it to work was not hard, but I'm having a problem with URI segments if I want "subcategories".

Example:

I have a home controller and a browse function. I set the base_url to home/browse and it works -- but when I add a "tag" (making the url home/browse/$tag) it obviously no longer works with the offset.

Here is my code right now:

Code:
## Browse podcasts
    ## Shows directory -- display with latest podcasts first
    function browse($tag)
    {
        if($tag!='')
        {
            // load pagination class
            $this->load->library('pagination');
            $config['base_url'] = base_url().'home/browse/'.$tag;
            
            $this->db->where('name',$tag);
            $counter_q = $this->db->get('tags');
            $counter_r = $counter_q->row();
            
            $this->db->where('tag_id',$counter_r->id);
            $this->db->from('podcasts');
            $config['total_rows'] = $this->db->count_all_results();
            $config['per_page'] = '6';
            $config['full_tag_open'] = '<div class="Paginator">';
            $config['full_tag_close'] = '</div>';
            $config['first_link'] = 'First';
            $config['last_link'] = 'Last';
            $config['cur_tag_open'] = '<b>';
            $config['cur_tag_close'] = '</b>';
            $config['prev_link'] = 'Prev';
            $config['next_link'] = 'Next';
            
            $this->pagination->initialize($config);
        
            //load the model and get results
            $this->load->model('podcast_model');
            $d['results'] = $this->podcast_model->get_podcast_tagged($config['per_page'],$this->uri->segment(3),$tag);    
        } else {
            // load pagination class
            $this->load->library('pagination');
            $config['base_url'] = base_url().'home/browse';
            $config['total_rows'] = $this->db->count_all('podcasts');
            $config['per_page'] = '6';
            $config['full_tag_open'] = '<div class="Paginator">';
            $config['full_tag_close'] = '</div>';
            $config['first_link'] = 'First';
            $config['last_link'] = 'Last';
            $config['cur_tag_open'] = '<b>';
            $config['cur_tag_close'] = '</b>';
            $config['prev_link'] = 'Prev';
            $config['next_link'] = 'Next';
            
            $this->pagination->initialize($config);
        
            //load the model and get results
            $this->load->model('podcast_model');
            $d['results'] = $this->podcast_model->get_podcast($config['per_page'],$this->uri->segment(3));
        }

Any ideas? Thanks!
#2

[eluser]Seppo[/eluser]
You must set uri_segment to 4 if you wanna add another parameter.




Theme © iAndrew 2016 - Forum software by © MyBB