From 5696374de382414cec9123e090a7d6df854e5934 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/conclusion.html | 2 +- user_guide/tutorial/create_news_items.html | 8 +-- user_guide/tutorial/hard_coded_pages.html | 7 +- user_guide/tutorial/index.html | 101 +++++++++++++++++++++++++++++ user_guide/tutorial/introduction.html | 101 ----------------------------- user_guide/tutorial/news_section.html | 29 +++------ user_guide/tutorial/static_pages.html | 16 ++--- 7 files changed, 126 insertions(+), 138 deletions(-) create mode 100644 user_guide/tutorial/index.html delete mode 100644 user_guide/tutorial/introduction.html (limited to 'user_guide/tutorial') diff --git a/user_guide/tutorial/conclusion.html b/user_guide/tutorial/conclusion.html index f3bdaad1d..ccf89175f 100644 --- a/user_guide/tutorial/conclusion.html +++ b/user_guide/tutorial/conclusion.html @@ -42,7 +42,7 @@ CodeIgniter Home  ›  User Guide Home  ›  -Tutorial  ›  +Tutorial  ›  Conclusion
Search User Guide   
diff --git a/user_guide/tutorial/create_news_items.html b/user_guide/tutorial/create_news_items.html index a25917930..48c82c799 100644 --- a/user_guide/tutorial/create_news_items.html +++ b/user_guide/tutorial/create_news_items.html @@ -42,7 +42,7 @@ CodeIgniter Home  ›  User Guide Home  ›  -Tutorial  ›  +Tutorial  ›  Create news items
Search User Guide   
@@ -90,7 +90,7 @@ Create news items

Go back to your news controller. You're going to do two things here, check whether the form was submitted and whether the submitted data passed the validation rules. You'll use the form validation library to do this.

-function create()
+public function create()
 {
 	$this->load->helper('form');
 	$this->load->library('form_validation');
@@ -112,7 +112,6 @@ function create()
 		$this->news_model->set_news();
 		$this->load->view('news/success');
 	}
-	
 }
 
@@ -127,7 +126,7 @@ function create()

The only thing that remains is writing a method that writes the data to the database. You'll use the Active Record class to insert the information and use the input library to get the posted data. Open up the model created earlier and add the following:

-function set_news()
+public function set_news()
 {
 	$this->load->helper('url');
 	
@@ -140,7 +139,6 @@ function set_news()
 	);
 	
 	return $this->db->insert('news', $data);
-	
 }
 
diff --git a/user_guide/tutorial/hard_coded_pages.html b/user_guide/tutorial/hard_coded_pages.html index e83f1ec80..408634a78 100644 --- a/user_guide/tutorial/hard_coded_pages.html +++ b/user_guide/tutorial/hard_coded_pages.html @@ -68,7 +68,7 @@ Features <?php class Pages extends CI_Controller { - function view($page = 'home') + public function view($page = 'home') { } @@ -104,7 +104,7 @@ class Pages extends CI_Controller {

In order to load these pages we'll have to check whether these page actually exists. When the page does exist, we load the view for that pages, including the header and footer and display it to the user. If it doesn't, we show a "404 Page not found" error.

diff --git a/user_guide/tutorial/index.html b/user_guide/tutorial/index.html new file mode 100644 index 000000000..4f665fe0a --- /dev/null +++ b/user_guide/tutorial/index.html @@ -0,0 +1,101 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial − Introduction

+ +

This tutorial is intended to introduce you to the CodeIgniter framework and the basic principles of MVC architecture. It will show you how a basic CodeIgniter application is constructed in step-by-step fashion.

+ +

In this tutorial, you will be creating a basic news application. You will begin by writing the code that can load static pages. Next, you will create a news section that reads news items from a database. Finally, you'll add a form to create news items in the database.

+ +

This tutorial will primarily focus on:

+ + +

The entire tutorial is split up over several pages, each explaining a small part of the functionality of the CodeIgniter framework. You'll go through the following pages:

+ + +

Enjoy your exploration of the CodeIgniter framework.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide/tutorial/introduction.html b/user_guide/tutorial/introduction.html deleted file mode 100644 index 78fd00b61..000000000 --- a/user_guide/tutorial/introduction.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial − Introduction

- -

This tutorial is intended to introduce you to the CodeIgniter framework and the basic principles of MVC architecture. It will show you how a basic CodeIgniter application is constructed in step-by-step fashion.

- -

In this tutorial, you will be creating a basic news application. You will begin by writing the code that can load static pages. Next, you will create a news section that reads news items from a database. Finally, you'll add a form to create news items in the database.

- -

This tutorial will primarily focus on:

- - -

The entire tutorial is split up over several pages, each explaining a small part of the functionality of the CodeIgniter framework. You'll go through the following pages:

- - -

Enjoy your exploration of the CodeIgniter framework.

- -
- - - - - - - \ No newline at end of file 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'];
 
diff --git a/user_guide/tutorial/static_pages.html b/user_guide/tutorial/static_pages.html index bf52f4543..51a04c689 100644 --- a/user_guide/tutorial/static_pages.html +++ b/user_guide/tutorial/static_pages.html @@ -42,7 +42,7 @@ CodeIgniter Home  ›  User Guide Home  ›  -Tutorial  ›  +Tutorial  ›  Static pages
Search User Guide   
@@ -79,7 +79,7 @@ As URL schemes become more complex, this may change. But for now, this is all we class Pages extends CI_Controller { - function view($page = 'home') + public function view($page = 'home') { } @@ -134,10 +134,10 @@ If you like to be particularly un-original, try "Hello World!".

In order to load those pages, you'll have to check whether the requested page actually exists:

-function view($page = 'home')
+public function view($page = 'home')
 {
 			
-	if ( ! file_exists('application/views/pages/' . $page . '.php'))
+	if ( ! file_exists('application/views/pages/'.$page.'.php'))
 	{
 		// Whoops, we don't have a page for that!
 		show_404();
@@ -146,10 +146,10 @@ function view($page = 'home')
 	$data['title'] = ucfirst($page); // Capitalize the first letter
 	
 	$this->load->view('templates/header', $data);
-	$this->load->view('pages/' . $page, $data);
+	$this->load->view('pages/'.$page, $data);
 	$this->load->view('templates/footer', $data);
-	
-}	
+
+}
 

Now, when the page does exist, it is loaded, including the header and footer, and displayed to the user. If the page doesn't exist, a "404 Page not found" error is shown.

@@ -193,7 +193,7 @@ in the pages controller? Awesome!