Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [code]
- public function get_news($id = FALSE)
- {
- if ($id === FALSE)
- {
- $this->db->join('news', 'news.author = users.id', 'left');
- $query = $this->db->get('news');
- return $query->result_array();
- }
- $this->db->join('news', 'news.author = users.id', 'left');
- $query = $this->db->get_where('news', array('id' => $id));
- return $query->row_array();}
- [/code]
- Controller, this is the controller part of it, that gets the news to the tamplate
- [code]
- public function index()
- {
- $data['news'] = $this->news_model->get_news();
- $data['title'] = 'News archive';
- $data['apptitle'] = "Zeta Dev News Page";
- $this->load->view('templates/header', $data);
- $this->load->view('news/index', $data);
- $this->load->view('templates/footer');
- }
- public function view($id)
- {
- $data2['news'] = $this->news_model->get_news($id);
- if (empty($data['news_item']))
- {
- //echo 'Nothing found :(';
- show_404();
- //return false;
- }
- $data['title'] = $data2['news']['title'];
- $data['apptitle'] = "Zeta Dev News Page";
- $this->load->view('templates/header', $data);
- $this->load->view('news/view', $data2);
- $this->load->view('templates/footer');
- }
- [/code]
- the index tamplate of news page (the news archive), the one called by index()
- [code]
- <b><a href="<?php $this->load->helper('url'); echo site_url('news/create'); ?>">Create an article</a></b>
- <hr>
- <?php foreach ($news as $news_item): ?>
- <?php
- $this->load->helper('date');
- $format = 'DATE_RFC822';
- $time = $news_item['date'];
- $FD = standard_date($format, $time);
- $U1= site_url('news/'.$news_item['id']);
- $U2= site_url('news/delete/'.$news_item['id']);
- $username= $news_item['username'];
- ?>
- <h2><?php echo $news_item['id'].' - '.$news_item['title'].' - Author:'.$username.' - Created on '.$FD ?></h2>
- <div id="main">
- <?php echo $news_item['text'] ?>
- </div>
- <?php
- echo '<p><a href="'.$U1.'">View article</a> <a href="'.$U2.'">Delete article</a></p>';
- ?> <hr>
- <?php endforeach ?>
- [/code]
- the view tamplate of the news page, called by view($id)
- [code]
- <?php
- $this->load->helper('url');
- $this->load->helper('date');
- $format = 'DATE_RFC822';
- $time = $news['date'];
- $FD = standard_date($format, $time);
- $id = $news['id'];
- $text = $news['text'];
- $title = $news['title'];
- $author = $news['username'];
- $segments1 = array('news');
- echo '<a href="'.site_url($segments1).'">Back to article Archive</a>';
- echo '<br><hr>';
- echo '<h2>'.$id.' - '.$title.' - Author:'.$author.' - Created on '.$FD.'</h2>';
- echo $text;
- echo '<hr>';
- [/code]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement