Advertisement
sinaga15

models & controller

Dec 3rd, 2017
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.84 KB | None | 0 0
  1. ini modelsnya
  2.  
  3.  
  4. public function get($slug) {
  5. //$sinaga = array();
  6.  
  7. $this->db->select('micom_news.*, micom_compartments.id, micom_compartments.title as nama');
  8. $this->db->from('micom_news');
  9. $this->db->join('micom_compartments', 'micom_compartments.id = micom_news.compartment','left');
  10. //$this->db->order_by('hits');
  11. $this->db->limit(5);
  12.  
  13. $sql = $this->db->get_where($this->read, array('micom_news.slug' =>isset($slug) ? $slug : ""));
  14.  
  15. $t = $sql->result_array();
  16. //return $t[0];
  17. return $t;
  18. //echo "<pre>";
  19. //print_r($t);
  20. //echo "</pre>";
  21.  
  22. //$t = $this->db->get($sql)->row_array();
  23. //return $this->db->get();
  24. }
  25.  
  26.  
  27. ----------------------------------------------------------------------------------------------------------------------------------
  28.  
  29.  
  30.  
  31. ini controller read detail
  32.  
  33.  
  34. public function detail($slug) {
  35. $this->load->model('data', 'detail');
  36. $this->load->library('form_validation');
  37.  
  38.  
  39. $t['read'] = $this->detail->all(10);
  40. //$t['detail'] = $this->detail->anjing($idartikel);
  41. $t['populer'] = $this->detail->populer();
  42. $t['kategori'] = $this->detail->kategori();
  43. $t['opini'] = $this->detail->all_opini(1);
  44.  
  45. $t['detail'] = $this->detail->get($slug);
  46.  
  47. //$t['title'] = $t['detail'][0]['title'];
  48. $t['title'] = $t['detail'][0]['title'];
  49. $t['category'] = $t['detail'][0]['title'];
  50. //echo "<pre>";
  51. //print_r($t['kategori']);
  52. //echo "</pre>";
  53. //$t['title'] = (isset($t['detail'][0]['title']) && $t['detail'][0]['title'] = "");
  54. //$t['image'] = (isset($t['detail'][0]['image']) && $t['detail'][0]['image'] = "");
  55.  
  56.  
  57. //echo '<pre>';
  58.  
  59. //$data = json_decode($t['detail'][0]['image'],true) ;
  60. //print_r($data);
  61.  
  62. //$t['image'] = $data['file'];
  63. //$file = json_decode($t['detail'][0]['image']);
  64. //$t['image'] = $file->file;
  65.  
  66. if(isset($t['detail'][0]['image'])){
  67. $raw_image = json_decode($t['detail'][0]['image'],true);
  68.  
  69. $t['detail'][0]['image'] = $raw_image['file'];
  70. //var_dump($t['detail'][0]['image']);
  71. }
  72. if(!$t['detail']) {
  73. //================error lagi deh============
  74. /*
  75. $this->load->view(
  76. 'Could not load the requested item',
  77. 'warning'
  78. );
  79. */
  80. redirect('read');
  81.  
  82. }
  83.  
  84.  
  85. $this->load->view("read/v_detail", $t);
  86.  
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement