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

[eluser]kr1pt[/eluser]
Model:

Code:
<?php

class Novosti_Model extends CI_Model
{
    /**
     * Novosti_Model::sve()
     *
     * Pronalaznje svih aktivnih ili neaktivnih novosti
     *
     * @access public
     * @return void
     */
    public function sve($aktivne = true)
    {
        $this->load->library('pagination');
        
        $config['base_url'] = base_url(). 'novosti/';
        $config['total_rows'] = $this->sve_broj(true);
        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<tr><td class="tablica" width="100%" colspan="5" style="text-align:center;">';
        $config['full_tag_close'] = '</td></tr>';
        $config['uri_segment'] = 2;
            
        
        $this->pagination->initialize($config);
        
        $aktivne = ($aktivne == true) ? 'aktivno' : 'neaktivno';
        
        $array = array('status' => $aktivne);
        $novosti = $this->db->order_by('id', 'DESC')->get_where('novosti', $array, $config['per_page'], $this->uri->segment(2));
        
        return $novosti->result_array();
    }
    
    /**
     * Novosti_Model::sve_broj()
     *
     * Broj svih aktivnih ili neaktivnih novosti
     *
     * @access public
     * @return void
     */
    public function sve_broj($aktivne = true)
    {
        $aktivne = ($aktivne == true) ? 'aktivno' : 'neaktivno';
        $array = array('status' => $aktivne);
        
        $novosti = $this->db->order_by('id', 'DESC')->get_where('novosti', $array);
        
        return $novosti->num_rows();
    }
}

/* End of file novosti_model.php */
/* Location: ./application/models/novosti_model.php */

And controller:
Code:
&lt;?php

class Novosti extends CI_Controller
{
    /**
     * Novosti::index()
     *
     * Zadnje napisane novosti portala
     *
     * @access public
     * @return void
     */
    public function index()
    {
        $this->load->model('Novosti_Model', 'novosti');
        
        // Uzimamo header
        $this->load->view('header');
        
        $data['sve_novosti'] = $this->novosti->sve(true);
        $data['broj_svih'] = $this->novosti->sve_broj(true);
        $data['logiran'] = $this->korisnik->prijavljen();
        $data['korisnik'] = $this->korisnik->uzmiPodatke();
        
        // Uzimamo dizajn naslovnice
        $this->load->view('novosti_index', $data);
        
        // Uzimamo footer
        $this->load->view('footer');
    }
    
}

/* End of file novosti.php */
/* Location: ./application/controllers/novosti.php */

My pagination does not work. When I go to:
http://localhost/zabavnjak/novosti/1

I get
Code:
404 Page Not Found

The page you requested was not found.

I've got only 2 rows in db so I put 1 per page.
#2

[eluser]Talifhani[/eluser]
Try watch this

http://net.tutsplus.com/articles/news/co...agination/
#3

[eluser]kr1pt[/eluser]
I do the same as him, but still 404.
#4

[eluser]Talifhani[/eluser]
oh sorry didnt really look.

Try do change this:
$config['base_url'] = base_url(). 'novosti/';

To this:
$config['base_url'] = base_url(). 'novosti/page';
#5

[eluser]kr1pt[/eluser]
Still nothing.

Code:
$redovi = $this->db->order_by('id', 'DESC')->get_where('novosti', array('status' => 'aktivno'))->num_rows();
        
        $config['base_url'] = base_url() . 'novosti/';
        $config['total_rows'] = $redovi;
        $config['per_page'] = 1;
        $config['num_links'] = 10;
        $config['full_tag_open'] = '<tr><td class="tablica" width="100%" colspan="5" style="text-align:center;">';
        $config['full_tag_close'] = '</td></tr>';
        $config['uri_segment'] = 2;
        
        $this->pagination->initialize($config);
        
        $data['broj_svih'] = $redovi;
        $data['logiran'] = $this->korisnik->prijavljen();
        $data['korisnik'] = $this->korisnik->uzmiPodatke();
        $data['sve_novosti'] = $this->db->order_by('id', 'DESC')->where('status', 'aktivno')->get('novosti', $config['per_page'], $this->uri->segment(2))->result_array();
        $data['linkovi'] = $this->pagination->create_links();

Why I get 404? :S And in second pagination everything works fine... I just copied code from other pagination and I still get 404.

EDITED: I can't use pagination in index() method obviously Smile Now works fine.
#6

[eluser]Talifhani[/eluser]
haha, silly rabit. I didnt even catch that. Good luck.

Also, i think you can if you specify
$config['base_url'] = base_url() . 'novosti/index/';

havent tried but, im sure you can. Almost
#7

[eluser]smartweb[/eluser]
Change router.php
#8

[eluser]Reneesh T K[/eluser]
I am here including a sample of how my pagination function looks and works for me:
in controller file:
function index(){
$configs['base_url'] = base_url()."customer_controller/index/";
$configs['per_page'] = '25';
$configs['num_links'] = 4;
$configs['prev_link'] = '«Previous';
$configs['next_link'] = 'Next»';
$configs['anchor_class'] = ' class="number" ';
$configs['cur_tag_open'] = ' <a class="number current">';
$configs['cur_tag_close'] = '</a>';
$configs['total_rows'] = $this->customer_model->getSiteUsers();
$this->pagination->initialize($configs);
$current_page = $this->uri->segment(3);
$current_page = ($current_page/$configs['per_page']) + 1;
$total_pages = ceil($configs['total_rows']/$configs['per_page']);
$data['page_info'] = "Page ( $current_page of $total_pages )";
$data['result'] = $this->customer_model->getSiteUsers($configs['per_page'],$this->uri->segment(3));
$data['pagination'] = $this->pagination->create_links();

$this->load->view('main.php',$data);
}


In Model:

function getSiteUsers($num=0,$offset=0)
{
$limit = "";
if($offset =="") $offset =0;
if($num !=0){
$limit = " limit $offset , $num ";
}
$query = "SELECT * from customers $limit";

$result = $this->db->query($query);
if($limit=="")
return $result->num_rows();
else
return $result->result_array();
}

In View :

<div class="pagination">&lt;? echo $page_info; ?&gt;&nbsp;&lt;?php echo $pagination;?&gt;</div>

Hope this is clear Smile
#9

[eluser]Unknown[/eluser]
If you load the models seperate lik:
Code:
$this->load->model('Novosti_Model');
$this->load->model(''novosti');

Does is it work then?




Theme © iAndrew 2016 - Forum software by © MyBB