From 7bd6335c77cfc5fec9e7e788d45d110c1b09ffd1 Mon Sep 17 00:00:00 2001 From: Joël Cox Date: Sat, 27 Aug 2011 20:21:19 +0200 Subject: Renamed introduction to index and small code style fixes (patch by @ericbarnes). --- user_guide/tutorial/news_section.html | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) (limited to 'user_guide/tutorial/news_section.html') diff --git a/user_guide/tutorial/news_section.html b/user_guide/tutorial/news_section.html index 191f0e1eb..b2d883184 100644 --- a/user_guide/tutorial/news_section.html +++ b/user_guide/tutorial/news_section.html @@ -42,7 +42,7 @@ CodeIgniter Home  ›  User Guide Home  ›  -Tutorial  ›  +Tutorial  ›  News section
Search User Guide   
@@ -71,10 +71,9 @@ News section <?php class News_model extends CI_Model { - function __construct() + public function __construct() { $this->load->database(); - } } @@ -97,18 +96,16 @@ CREATE TABLE news (

Now that the database and a model have been set up, you'll need a method to get all of our posts from our database. To do this, the database abstraction layer that is included with CodeIgniter — Active Record — is used. This makes it possible to write your 'queries' once and make them work on all supported database systems. Add the following code to your model.

-function get_news($slug = FALSE)
+public function get_news($slug = FALSE)
 {
 	if ($slug === FALSE)
 	{
 		$query = $this->db->get('news');
 		return $query->result_array();
-
 	}
 	
 	$query = $this->db->get_where('news', array('slug' => $slug));
 	return $query->row_array();
-
 }
 
@@ -120,27 +117,23 @@ function get_news($slug = FALSE)
 <?php
-class News extends CI_Controller{
+class News extends CI_Controller {
 
-	function __construct()
+	public function __construct()
 	{
 		parent::__construct();
 		$this->load->model('news_model');
-
 	}
 
-	function index()
+	public function index()
 	{
 		$data['news'] = $this->news_model->get_news();
-
 	}
 
-	function view($slug)
+	public function view($slug)
 	{
 		$data['news'] = $this->news_model->get_news($slug);
-
 	}
-
 }
 
@@ -151,7 +144,7 @@ class News extends CI_Controller{

Now the data is retrieved by the controller through our model, but nothing is displayed yet. The next thing to do is passing this data to the views.

-function index()
+public function index()
 {
 	$data['news'] = $this->news_model->get_news();
 	$data['title'] = 'News archive';
@@ -159,7 +152,6 @@ function index()
 	$this->load->view('templates/header', $data);
 	$this->load->view('news/index', $data);
 	$this->load->view('templates/footer');
-
 }
 
@@ -182,7 +174,7 @@ function index()

The news overview page is now done, but a page to display individual news items is still absent. The model created earlier is made in such way that it can easily be used for this functionality. You only need to add some code to the controller and create a new view. Go back to the news controller and add the following lines to the file.

-function view($slug)
+public function view($slug)
 {
 	$data['news_item'] = $this->news_model->get_news($slug);
 
@@ -196,7 +188,6 @@ function view($slug)
 	$this->load->view('templates/header', $data);
 	$this->load->view('news/view', $data);
 	$this->load->view('templates/footer');
-
 }
 
@@ -204,7 +195,7 @@ function view($slug)
 <?php
-echo '<h2>' . $news_item['title'] . '</h2>';
+echo '<h2>'.$news_item['title'].'</h2>';
 echo $news_item['text'];
 
-- cgit v1.2.3-24-g4f1b