[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:
<?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.