Advertisement
Guest User

nagata

a guest
Jun 6th, 2012
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.54 KB | None | 0 0
  1. [code]
  2.     public function get_news($id = FALSE)
  3. {
  4.     if ($id === FALSE)
  5.     {
  6.         $this->db->join('news', 'news.author = users.id', 'left');
  7.         $query = $this->db->get('news');
  8.  
  9.         return $query->result_array();
  10.     }
  11.     $this->db->join('news', 'news.author = users.id', 'left');
  12.     $query = $this->db->get_where('news', array('id' => $id));
  13.     return $query->row_array();}
  14. [/code]
  15.  
  16. Controller, this is the controller part of it, that gets the news to the tamplate
  17. [code]
  18.     public function index()
  19. {
  20.     $data['news'] = $this->news_model->get_news();
  21.     $data['title'] = 'News archive';
  22.     $data['apptitle'] = "Zeta Dev News Page";
  23.  
  24.     $this->load->view('templates/header', $data);
  25.     $this->load->view('news/index', $data);
  26.     $this->load->view('templates/footer');
  27. }
  28.  
  29. public function view($id)
  30. {
  31.     $data2['news'] = $this->news_model->get_news($id);
  32.     if (empty($data['news_item']))
  33.     {  
  34.         //echo 'Nothing found :(';
  35.         show_404();
  36.         //return false;
  37.     }
  38.     $data['title'] = $data2['news']['title'];
  39.     $data['apptitle'] = "Zeta Dev News Page";
  40.     $this->load->view('templates/header', $data);
  41.     $this->load->view('news/view', $data2);
  42.     $this->load->view('templates/footer');
  43. }
  44. [/code]
  45.  
  46. the index tamplate of news page (the news archive), the one called by index()
  47. [code]
  48. <b><a href="<?php  $this->load->helper('url'); echo  site_url('news/create'); ?>">Create an article</a></b>
  49. <hr>
  50.  
  51. <?php foreach ($news as $news_item): ?>
  52. <?php
  53.  
  54.     $this->load->helper('date');
  55.     $format = 'DATE_RFC822';
  56.     $time = $news_item['date'];
  57.     $FD = standard_date($format, $time);
  58.     $U1= site_url('news/'.$news_item['id']);
  59.     $U2= site_url('news/delete/'.$news_item['id']);
  60.  
  61.     $username= $news_item['username'];
  62. ?>
  63.     <h2><?php echo $news_item['id'].' - '.$news_item['title'].' - Author:'.$username.' - Created on '.$FD ?></h2>
  64.     <div id="main">
  65.         <?php echo $news_item['text'] ?>
  66.     </div>
  67. <?php
  68. echo  '<p><a href="'.$U1.'">View article</a> <a href="'.$U2.'">Delete article</a></p>';
  69. ?>   <hr>
  70. <?php endforeach ?>
  71.  
  72. [/code]
  73. the view tamplate of the news page, called by view($id)
  74. [code]
  75. <?php
  76.     $this->load->helper('url');
  77.     $this->load->helper('date');
  78.     $format = 'DATE_RFC822';
  79.     $time = $news['date'];
  80.     $FD = standard_date($format, $time);
  81.     $id = $news['id'];
  82.     $text = $news['text'];
  83.     $title = $news['title'];
  84.     $author = $news['username'];
  85.     $segments1 = array('news');
  86.    
  87.    
  88. echo '<a href="'.site_url($segments1).'">Back to article Archive</a>';
  89. echo '<br><hr>';
  90. echo '<h2>'.$id.' - '.$title.' - Author:'.$author.' - Created on '.$FD.'</h2>';
  91. echo $text;
  92. echo '<hr>';
  93.  
  94. [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement