summaryrefslogtreecommitdiffstats
path: root/user_guide/tutorial
diff options
context:
space:
mode:
authorWes Baker <wes@wesbaker.com>2013-07-08 23:22:21 +0200
committerWes Baker <wes@wesbaker.com>2013-07-08 23:22:21 +0200
commitc5f99fdcc5c4a918b5b8fe3ddbd56ab25ad1c22b (patch)
tree9078f2e847bee8adab51598e6a3e08e6e325dc38 /user_guide/tutorial
parent4c866e0b911fcc82cf49b317178788ce3c319bd4 (diff)
Updating User Guide for 2.1.4.
Diffstat (limited to 'user_guide/tutorial')
-rw-r--r--user_guide/tutorial/conclusion.html2
-rw-r--r--user_guide/tutorial/create_news_items.html28
-rw-r--r--user_guide/tutorial/hard_coded_pages.html24
-rw-r--r--user_guide/tutorial/index.html4
-rw-r--r--user_guide/tutorial/news_section.html4
-rw-r--r--user_guide/tutorial/static_pages.html24
6 files changed, 43 insertions, 43 deletions
diff --git a/user_guide/tutorial/conclusion.html b/user_guide/tutorial/conclusion.html
index a439ac131..68daed771 100644
--- a/user_guide/tutorial/conclusion.html
+++ b/user_guide/tutorial/conclusion.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
diff --git a/user_guide/tutorial/create_news_items.html b/user_guide/tutorial/create_news_items.html
index 853044c0c..8effe35ef 100644
--- a/user_guide/tutorial/create_news_items.html
+++ b/user_guide/tutorial/create_news_items.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -72,13 +72,13 @@ Create news items
&lt;?php echo form_open('news/create') ?>
- <label for="title">Title</label>
+ <label for="title">Title</label>
<input type="input" name="title" /><br />
<label for="text">Text</label>
<textarea name="text">&lt;/textarea><br />
-
- <input type="submit" name="submit" value="Create news item" />
+
+ <input type="submit" name="submit" value="Create news item" />
&lt;/form>
</textarea>
@@ -94,18 +94,18 @@ public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
-
+
$data['title'] = 'Create a news item';
-
+
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'text', 'required');
-
+
if ($this->form_validation->run() === FALSE)
{
- $this->load->view('templates/header', $data);
+ $this->load->view('templates/header', $data);
$this->load->view('news/create');
$this->load->view('templates/footer');
-
+
}
else
{
@@ -129,27 +129,27 @@ public function create()
public function set_news()
{
$this->load->helper('url');
-
+
$slug = url_title($this->input->post('title'), 'dash', TRUE);
-
+
$data = array(
'title' => $this->input->post('title'),
'slug' => $slug,
'text' => $this->input->post('text')
);
-
+
return $this->db->insert('news', $data);
}
</pre>
<p>This new method takes care of inserting the news item into the database. The third line contains a new function, <dfn>url_title()</dfn>. This function - provided by the <a href="../helpers/url_helper.html">URL helper</a> - strips down the string you pass it, replacing all spaces by dashes (-) and makes sure everything is in lowercase characters. This leaves you with a nice slug, perfect for creating URIs.</p>
-
+
<p>Let's continue with preparing the record that is going to be inserted later, inside the <var>$data</var> array. Each element corresponds with a column in the database table created earlier. You might notice a new method here, namely the <dfn>post()</dfn> method from the <a href="../libraries/input.html">input library</a>. This method makes sure the data is sanitized, protecting you from nasty attacks from others. The input library is loaded by default. At last, you insert our <var>$data</var> array into our database.</p>
<h2>Routing</h2>
<p>Before you can start adding news items into your CodeIgniter application you have to add an extra rule to <dfn>config/routes.php</dfn> file. Make sure your file contains the following. This makes sure CodeIgniter sees 'create' as a method instead of a news item's slug.</p>
-
+
<pre>
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
diff --git a/user_guide/tutorial/hard_coded_pages.html b/user_guide/tutorial/hard_coded_pages.html
index 2f4218222..77ad7f2dd 100644
--- a/user_guide/tutorial/hard_coded_pages.html
+++ b/user_guide/tutorial/hard_coded_pages.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -86,13 +86,13 @@ class Pages extends CI_Controller {
</head>
<body>
<h1>CodeIgniter 2 Tutorial</h1>
-
+
</textarea>
<p>Our header doesn't do anything exciting. It contains the basic HTML code that we will want to display before loading the main view. You can also see that we echo the <var>$title</var> variable, which we didn't define. We will set this variable in the Pages controller a bit later. Let's go ahead and create a footer at <dfn>application/views/templates/footer.php</dfn> that includes the following code.</p>
-
+
<textarea class="textarea" style="width:100%" cols="50" rows="4">
-<strong>&copy; 2011</strong>
+<strong>&copy; 2011</strong>
</body>
</html>
</textarea>
@@ -106,36 +106,36 @@ class Pages extends CI_Controller {
<textarea class="textarea" style="width:100%" cols="50" rows="16">
public function view($page = 'home')
{
-
+
if ( ! file_exists('application/views/pages/' . $page . EXT))
{
show_404();
}
-
+
$data['title'] = ucfirst($page);
-
+
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page);
$this->load->view('templates/footer');
-}
+}
</textarea>
<p>The first thing we do is checking whether the page we're looking for does actually exist. We use PHP's native file_exists() to do this check and pass the path where the file is supposed to be. Next is the function show_404(), a CodeIgniter function that renders the default error page and sets the appropriate HTTP headers.</p>
-<p>In the header template you saw we were using the <var>$title</var> variable to customize our page title. This is where we define the title, but instead of assigning the value to a variable, we assign it to the title element in the <var>$data</var> array. The last thing we need to do is loading the views in the order we want them to be displayed. We also pass the <var>$data</var> array to the header view to make its elements available in the header view file.<p>
-
+<p>In the header template you saw we were using the <var>$title</var> variable to customize our page title. This is where we define the title, but instead of assigning the value to a variable, we assign it to the title element in the <var>$data</var> array. The last thing we need to do is loading the views in the order we want them to be displayed. We also pass the <var>$data</var> array to the header view to make its elements available in the header view file.<p>
+
<h2>Routing</h2>
<p>Actually, our controller is already functioning. Point your browser to <dfn>index.php/pages/view</dfn> to see your homepage. When you visit <dfn>index.php/pages/view/about</dfn> you will see the about page, again including your header and footer. Now we're going to get rid of the pages/view part in our URI. As you may have seen, CodeIgniter does its routing by the class, method and parameter, separated by slashes.</p>
<p>Open the routing file located at <dfn>application/config/routes.php</dfn> and add the following two lines. Remove all other code that sets any element in the <var>$route</var> array.</p>
-
+
<textarea class="textarea" style="width:100%" cols="50" rows="3">
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
</textarea>
-<p>CodeIgniter reads its routing rules from top to bottom and routes the request to the first matching rule. These routes are stored in the <var>$route</var> array where the keys represent the incoming request and the value the path to the method, as described above.</p>
+<p>CodeIgniter reads its routing rules from top to bottom and routes the request to the first matching rule. These routes are stored in the <var>$route</var> array where the keys represent the incoming request and the value the path to the method, as described above.</p>
<p>The first rule in our <var>$routes</var> array matches every request - using the wildcard operator <dfn>(:any)</dfn> - and passes the value to the view method of the pages class we created earlier. The default controller route makes sure every request to the root goes to the view method as well, which has the first parameter set to 'home' by default.</p>
diff --git a/user_guide/tutorial/index.html b/user_guide/tutorial/index.html
index e5648f9e3..5baf52c6b 100644
--- a/user_guide/tutorial/index.html
+++ b/user_guide/tutorial/index.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -59,7 +59,7 @@ Introduction
<h1>Tutorial &minus; Introduction</h1>
-<p>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.</p>
+<p>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.</p>
<p>In this tutorial, you will be creating a <strong>basic news application</strong>. 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.</p>
diff --git a/user_guide/tutorial/news_section.html b/user_guide/tutorial/news_section.html
index 64c693246..db199848c 100644
--- a/user_guide/tutorial/news_section.html
+++ b/user_guide/tutorial/news_section.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -103,7 +103,7 @@ public function get_news($slug = FALSE)
$query = $this->db->get('news');
return $query->result_array();
}
-
+
$query = $this->db->get_where('news', array('slug' => $slug));
return $query->row_array();
}
diff --git a/user_guide/tutorial/static_pages.html b/user_guide/tutorial/static_pages.html
index 13e406358..be05436ef 100644
--- a/user_guide/tutorial/static_pages.html
+++ b/user_guide/tutorial/static_pages.html
@@ -28,7 +28,7 @@
<div id="masthead">
<table cellpadding="0" cellspacing="0" border="0" style="width:100%">
<tr>
-<td><h1>CodeIgniter User Guide Version 2.1.3</h1></td>
+<td><h1>CodeIgniter User Guide Version Location</h1></td>
<td id="breadcrumb_right"><a href="../toc.html">Table of Contents Page</a></td>
</tr>
</table>
@@ -109,15 +109,15 @@ We will be creating two &quot;views&quot; (page templates) that act as our page
</head>
<body>
<h1>CodeIgniter 2 Tutorial</h1>
-
+
</textarea>
-<p>The header contains the basic HTML code that you'll want to display before loading the main view, together with a heading.
+<p>The header contains the basic HTML code that you'll want to display before loading the main view, together with a heading.
It will also output the <var>$title</var> variable, which we'll define later in the controller.
Now create a footer at <dfn>application/views/templates/footer.php</dfn> that includes the following code:</p>
-
+
<textarea class="textarea" style="width:100%" cols="50" rows="4">
-<strong>&#38;copy; 2011</strong>
+<strong>&#38;copy; 2011</strong>
</body>
</html>
</textarea>
@@ -127,8 +127,8 @@ Now create a footer at <dfn>application/views/templates/footer.php</dfn> that in
<p>Earlier you set up a controller with a view() method. The method accepts one parameter, which is the name of the page to be loaded.
The static page templates will be located in the <dfn>application/views/pages/</dfn> directory.</p>
-<p>In that directory, create two files named <dfn>home.php</dfn> and <dfn>about.php</dfn>.
-Within those files, type some text &minus; anything you'd like &minus; and save them.
+<p>In that directory, create two files named <dfn>home.php</dfn> and <dfn>about.php</dfn>.
+Within those files, type some text &minus; anything you'd like &minus; and save them.
If you like to be particularly un-original, try &quot;Hello World!&quot;.</p>
<p>In order to load those pages, you'll have to check whether the requested page actually exists:</p>
@@ -136,15 +136,15 @@ If you like to be particularly un-original, try &quot;Hello World!&quot;.</p>
<pre>
public function view($page = 'home')
{
-
+
if ( ! file_exists('application/views/pages/'.$page.'.php'))
{
// Whoops, we don't have a page for that!
show_404();
}
-
+
$data['title'] = ucfirst($page); // Capitalize the first letter
-
+
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
@@ -160,7 +160,7 @@ public function view($page = 'home')
<p>The last thing that has to be done is loading the views in the order they should be displayed.
The second parameter in the <var>view()</var> method is used to pass values to the view. Each value in the <var>$data</var> array is assigned to a variable with the name of its key. So the value of <var>$data['title']</var> in the controller is equivalent to $title in the view.<p>
-
+
<h2>Routing</h2>
<p>The controller is now functioning! Point your browser to <dfn>[your-site-url]index.php/pages/view</dfn> to see your page. When you visit <dfn>index.php/pages/view/about</dfn> you'll see the about page, again including the header and footer.</p>
@@ -169,7 +169,7 @@ The second parameter in the <var>view()</var> method is used to pass values to t
<code>http://example.com/[controller-class]/[controller-method]/[arguments]</code></p>
<p>Let's do that. Open the routing file located at <dfn>application/config/routes.php</dfn> and add the following two lines. Remove all other code that sets any element in the <var>$route</var> array.</p>
-
+
<pre>
$route['default_controller'] = 'pages/view';
$route['(:any)'] = 'pages/view/$1';