SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | // defined('BASEPATH') OR exit('No direct script access allowed');
| |
| 3 | if (false) {
| |
| 4 | - | class Indeks extends CI_Controller {
|
| 4 | + | echo 'hi'; |
| 5 | } | |
| 6 | - | // public function __construct() {
|
| 6 | + | |
| 7 | - | // parent::__construct(); |
| 7 | + | class Indeks extends CI_Controller |
| 8 | - | // } |
| 8 | + | {
|
| 9 | - | /** |
| 9 | + | |
| 10 | - | * Index Page for this controller. |
| 10 | + | // public function __construct() {
|
| 11 | - | * |
| 11 | + | // parent::__construct(); |
| 12 | - | * Maps to the following URL |
| 12 | + | // } |
| 13 | - | * http://example.com/index.php/welcome |
| 13 | + | |
| 14 | - | * - or - |
| 14 | + | |
| 15 | - | * http://example.com/index.php/welcome/index |
| 15 | + | public function index($indeks=0) |
| 16 | - | * - or - |
| 16 | + | {
|
| 17 | - | * Since this controller is set as the default controller in |
| 17 | + | |
| 18 | - | * config/routes.php, it's displayed at http://example.com/ |
| 18 | + | redirect('indeks');
|
| 19 | - | * |
| 19 | + | |
| 20 | - | * So any other public methods not prefixed with an underscore will |
| 20 | + | |
| 21 | - | * map to /index.php/welcome/<method_name> |
| 21 | + | |
| 22 | - | * @see https://codeigniter.com/user_guide/general/urls.html |
| 22 | + | |
| 23 | - | */ |
| 23 | + | $this->load->helper('content');
|
| 24 | - | /* |
| 24 | + | |
| 25 | - | public function __construct() {
|
| 25 | + | |
| 26 | $this->output->delete_cache(); | |
| 27 | - | parent::__construct(); |
| 27 | + | |
| 28 | $t['title'] = 'Kumpulan Berita Hari ini'; | |
| 29 | - | $this->load->library('session');
|
| 29 | + | |
| 30 | - | $this->load->helper('date');
|
| 30 | + | |
| 31 | ||
| 32 | $offset = 20; | |
| 33 | $pagging = (int) $this->uri->segment(3, 0); | |
| 34 | - | */ |
| 34 | + | |
| 35 | #Pagination Start | |
| 36 | - | public function index($indeks=0) {
|
| 36 | + | $total_data = $this->indeks->total_news($indeks); |
| 37 | $t['end_page'] = ($total_data >= 20) ? true : false; | |
| 38 | - | redirect('indeks');
|
| 38 | + | |
| 39 | $next = (int) $pagging + 20; | |
| 40 | $prev = (int) $pagging - 20; | |
| 41 | ||
| 42 | $params=array( | |
| 43 | - | $this->load->helper('content');
|
| 43 | + | 'limit'=>$pagging, |
| 44 | 'start'=>$start | |
| 45 | ); | |
| 46 | $t['indeks'] = $this->indeks->gets($indeks, $params); | |
| 47 | $raws_image = json_decode($t['indeks'][0]['image'], true) ; | |
| 48 | ||
| 49 | $pagination = ""; | |
| 50 | //prev button | |
| 51 | if ($pagging > 0) {
| |
| 52 | - | $t['indeks'] = $this->indeks->all_news($indeks); |
| 52 | + | |
| 53 | - | $raws_image = json_decode($t['indeks'][0]['image'],true) ; |
| 53 | + | |
| 54 | - | |
| 54 | + | |
| 55 | - | $offset = 20; |
| 55 | + | |
| 56 | - | $pagging = (int) $this->uri->segment(3,0); |
| 56 | + | if ($t['end_page']) {
|
| 57 | $pagination.= '<li><a href="'.base_url().'indeks/index/'.$next.'" title="next">Next</a></li>'; | |
| 58 | } | |
| 59 | - | $total_data = count($t['indeks']); |
| 59 | + | |
| 60 | - | $t['end_page'] = ($total_data >= 20) ? TRUE : FALSE; |
| 60 | + | |
| 61 | ||
| 62 | #Menu | |
| 63 | $t['v_menu'] = $this->load->view('template/v_menu', null, true);
| |
| 64 | #Footer | |
| 65 | $t['v_footer'] = $this->load->view('template/v_footer', null, true);
| |
| 66 | ||
| 67 | - | if ($pagging > 0) |
| 67 | + | $this->load->view('pages/v_index', $t, false);
|
| 68 | } | |
| 69 | } | |
| 70 | ||
| 71 | - | if ($t['end_page']) |
| 71 | + | //======================MODEL================================= |
| 72 | /** | |
| 73 | * mengembalikan nilai total news | |
| 74 | */ | |
| 75 | function total_news($id=0) | |
| 76 | {
| |
| 77 | - | $t['v_menu'] = $this->load->view('template/v_menu',NULL,TRUE);
|
| 77 | + | $this->db->select("count(*) c")
|
| 78 | - | #Footer |
| 78 | + | ->where('id_cat', $id);
|
| 79 | - | $t['v_footer'] = $this->load->view('template/v_footer',NULL,TRUE);
|
| 79 | + | $que=$this->db->get('table');
|
| 80 | - | |
| 80 | + | return $que->c; //angka |
| 81 | - | $this->load->view('pages/v_index' ,$t,FALSE);
|
| 81 | + | } |
| 82 | /*** | |
| 83 | * mengembalikan informasi.. semua parameter taro di params.. harusnya id artkel juga | |
| 84 | * penamaan bisa diganti agar jelas | |
| 85 | */ | |
| 86 | function gets($id=0, $params=array()) | |
| 87 | {
| |
| 88 | $this->db->from('table');
| |
| 89 | if ($id!=0) {
| |
| 90 | $this->db->where('id_cat', $id);
| |
| 91 | } | |
| 92 | $start=isset($params['start'])?$params['start']:0; | |
| 93 | $limit=isset($params['limit'])?$params['limit']:10; | |
| 94 | $this->db->limit($limit, $start); | |
| 95 | return $this->db->get()->result(); | |
| 96 | } |