Welcome Guest, Not a member yet? Register   Sign In
Pagination problem [SOLVED]
#1

[eluser]Ngulo[/eluser]
hi,i've a problem paginating data from db

here is my Controller

templates.php:
Code:
<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Templates extends Controller
{
    function Templates()
    {
        parent::Controller();
         if(!$this->session->userdata('admin'))
             {redirect('admin/home');}
        
    }
function index()
    {
          $this->load->library('pagination');
        $offset=$this->uri->segment(3);

        $limit=3;

        $this->db->limit($limit, $offset);
        $query = $this->db->get('joomla_templx');
        $config['per_page'] = $limit;
        $config['base_url'] = site_url() . '/admin/templates/';
        $config['total_rows'] = $this->db->count_all('joomla_templx');

        $config['first_link']   = 'Primo';
    $config['next_link']    = 'avanti';
    $config['prev_link']    = 'indietro';
        $config['last_link']    = 'Ultimo';
        $this->pagination->initialize($config);
        $paginator=$this->pagination->create_links();

        $data = array( 'query' => $query, 'paginator'=>$paginator);


        $this->load->view('admin/templates_view',$data);
    


      
    }
}
/*end of file templates.php*/

the pagination is working ,and i see perfectly pagination links... but when i click on pagination links the page take me back an error:
Code:
404 Page Not Found

The page you requested was not found.

the links are good beacuse they takes me to the base url i have set for $offset :
Code:
www.asd.com/index.php/admin/templates/offset(1...or...2...or ....3...)

p:s:i'm still not using .htaccess

why? :O
#2

[eluser]karloff[/eluser]
maybe using routes would be the answer?

Code:
$route['admin/templates/:num'] = "admin/templates";

probably not the best answer but I thought I'd throw it out there?
#3

[eluser]erik.brannstrom[/eluser]
The problem is that the controller will try to find a method with the name 1 (or 2 or 3..) since the method name always comes after the controller name in the URI. You probably need to specify your index method to be used in your base url, i.e. $config['base_url'] = site_url('admin/templates/index/'). Try it, I think that should do it..
#4

[eluser]Ngulo[/eluser]
yep,sorry guys Tongue
erik is right.....i fix the problem, before :
using $config[‘base_url’] = site_url(‘admin/templates/index/’)

and after i've just put the $config

uri-segment to (4) instead of (3) (default) ,now the segment is catch!!!

thanks a lot for supporting Wink
#5

[eluser]tulasi[/eluser]
Hi, i have a problem.
i used $config[‘base_url’] = site_url(‘admin/templates/index/’)
and uri-segment to (4)
pagination is working for me but i always see '1' as highlited (i.e nolink for it) and previous link(<<) not found.
Can someone please help?
#6

[eluser]Aken[/eluser]
Need to post your code.
#7

[eluser]tulasi[/eluser]
Code:
class Logstats extends CI_Controller {

function __construct() {
        parent::__construct();
    
  $this->load->model('admin_logstat');
  $this->load->model('common_model');
     $this->load->helper(array('form', 'url'));  
  $this->load->library('form_validation');
  $this->load->library('pagination');
  $this->load->library('common');
}


function index()
{  
    
      $ofset=0;
   $config['base_url'] = site_url('index.php/admin/logstats/index/');    
        $config['total_rows'] = $this->common_model->get_countt('garages','1','1');
        $config['per_page'] = '2';
   $config['use_page_numbers'] = TRUE;
         $config['full_tag_open'] = '<p align="center">';
         $config['full_tag_close'] = '</p>';

         $this->pagination->initialize($config);  
   if($this->uri->segment(4))
   $ofset=($this->uri->segment(4)-1)*$config['per_page'];
              
        $data['det']=$this->admin_logstat->view_stats($ofset,$config['per_page']);


  $this->load->admin_template('stats/view',$data);

}
}
#8

[eluser]Aken[/eluser]
You need to set the uri_segment config option for the pagination to know which page it's on.
#9

[eluser]tulasi[/eluser]
Thanks for your fast reply. Its working....




Theme © iAndrew 2016 - Forum software by © MyBB