<?php

class Noticias extends MY_Controller {

    public $noticias = array();

    function __construct() {
        parent::__construct();
    }

    function index() {
        $this->show_noticias();
    }
    
    function show_noticias() {
        
        $this->title = $this->lang->line('Noticias');
        
        
        $this->load->model('noticia_model');

        $offset = $this->uri->segment(2);

        $this->load->library('pagination');
        $this->load->library('table');

        $config['per_page'] = 4;

        $config['base_url'] = base_url() . $this->uri->segment(1);
        $config['total_rows'] = $this->noticia_model->get_count_noticias();
        $config['uri_segment'] = 2;

        $config['num_links'] = 3;
        
        $config['last_link'] = '>>';
        $config['last_tag_open'] = '<div class="number">';
        $config['last_tag_close'] = '</div>';
        
        $config['first_link'] = '<<';
        $config['first_tag_open'] = '<div class="number">';
        $config['first_tag_close'] = '</div>';

        $config['prev_link'] = '<';
        $config['prev_tag_open'] = '<div class="number"><span>';
        $config['prev_tag_close'] = '</span></div>';

        $config['next_link'] = '>';
        $config['next_tag_open'] = '<div class="number"><span>';
        $config['next_tag_close'] = '</span></div>';

        $config['cur_tag_open'] = '<div class="number active"><a><span>';
        $config['cur_tag_close'] = '</span></a></div>';

        $config['num_tag_open'] = '<div class="number"><span>';
        $config['num_tag_close'] = '</span></div>';


        $this->pagination->initialize($config);

        $noticias_data = $this->noticia_model->get_all_noticias($config['per_page'], $offset);
        if ($noticias_data->num_rows > 0) {
            $this->noticias = $noticias_data->result_array();
        }
        
        
        parent::renderPage('noticias_view');
    }
    
}

