summaryrefslogtreecommitdiffstats
path: root/user_guide/tutorial/create_news_items.html
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide/tutorial/create_news_items.html')
-rw-r--r--user_guide/tutorial/create_news_items.html28
1 files changed, 14 insertions, 14 deletions
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';