summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source')
-rw-r--r--user_guide_src/source/index.rst3
-rw-r--r--user_guide_src/source/tutorial/conclusion.rst5
-rw-r--r--user_guide_src/source/tutorial/create_news_items.rst29
-rw-r--r--user_guide_src/source/tutorial/hard_coded_pages.rst73
-rw-r--r--user_guide_src/source/tutorial/index.rst16
-rw-r--r--user_guide_src/source/tutorial/news_section.rst7
-rw-r--r--user_guide_src/source/tutorial/static_pages.rst40
7 files changed, 74 insertions, 99 deletions
diff --git a/user_guide_src/source/index.rst b/user_guide_src/source/index.rst
index e53182550..0e6bc5003 100644
--- a/user_guide_src/source/index.rst
+++ b/user_guide_src/source/index.rst
@@ -42,4 +42,5 @@ CodeIgniter is right for you if:
libraries/index
database/index
helpers/index
- documentation/index \ No newline at end of file
+ documentation/index
+ tutorial/index \ No newline at end of file
diff --git a/user_guide_src/source/tutorial/conclusion.rst b/user_guide_src/source/tutorial/conclusion.rst
index 3b193d63d..48fbdcc8a 100644
--- a/user_guide_src/source/tutorial/conclusion.rst
+++ b/user_guide_src/source/tutorial/conclusion.rst
@@ -1,5 +1,6 @@
-Tutorial - Conclusion
-=====================
+##########
+Conclusion
+##########
This tutorial did not cover all of the things you might expect of a
full-fledged content management system, but it introduced you to the
diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst
index 4a0056ada..003b94bd8 100644
--- a/user_guide_src/source/tutorial/create_news_items.rst
+++ b/user_guide_src/source/tutorial/create_news_items.rst
@@ -1,5 +1,6 @@
-Tutorial - Create news items
-============================
+#################
+Create news items
+#################
You now know how you can read data from a database using CodeIgnite, but
you haven't written any information to the database yet. In this section
@@ -15,16 +16,26 @@ with two fields, one for the title and one for the text. You'll derive
the slug from our title in the model. Create the new view at
application/views/news/create.php.
-Create a news item
-------------------
+::
+
+ <h2>Create a news item</h2>
+
+ <?php echo validation_errors(); ?>
+
+ <?php echo form_open('news/create') ?>
+
+ <label for="title">Title</label>
+ <input type="input" name="title" /><br />
+
+ <label for="text">Text</label>
+ <textarea name="text"></textarea><br />
+
+ <input type="submit" name="submit" value="Create news item" />
-<?php echo validation\_errors(); ?> <?php echo form\_open('news/create')
-?> Title
- Text </textarea>
- </form>
+ </form>
There are only two things here that probably look unfamiliar to you: the
-form\_open() function and the validation\_errors() function.
+form_open() function and the validation_errors() function.
The first function is provided by the `form
helper <../helpers/form_helper.html>`_ and renders the form element and
diff --git a/user_guide_src/source/tutorial/hard_coded_pages.rst b/user_guide_src/source/tutorial/hard_coded_pages.rst
deleted file mode 100644
index c7b541768..000000000
--- a/user_guide_src/source/tutorial/hard_coded_pages.rst
+++ /dev/null
@@ -1,73 +0,0 @@
-CodeIgniter 2 Tutorial
-======================
-
-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 $title 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 application/views/templates/footer.php that
-includes the following code.
-
-**© 2011**
-
-Adding logic to the controller
-------------------------------
-
-Now we've set up the basics so we can finally do some real programming.
-Earlier we set up our controller with a view method. Because we don't
-want to write a separate method for every page, we made the view method
-accept one parameter, the name of the page. These hard coded pages will
-be located in application/views/pages/. Create two files in this
-directory named home.php and about.php and put in some HTML content.
-
-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.
-
-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'); }
-
-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.
-
-In the header template you saw we were using the $title 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 $data 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 $data array to
-the header view to make its elements available in the header view file.
-
-Routing
--------
-
-Actually, our controller is already functioning. Point your browser to
-index.php/pages/view to see your homepage. When you visit
-index.php/pages/view/about 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.
-
-Open the routing file located at application/config/routes.php and add
-the following two lines. Remove all other code that sets any element in
-the $route array.
-
-$route['(:any)'] = 'pages/view/$1'; $route['default\_controller'] =
-'pages/view';
-
-CodeIgniter reads its routing rules from top to bottom and routes the
-request to the first matching rule. These routes are stored in the
-$route array where the keys represent the incoming request and the value
-the path to the method, as described above.
-
-The first rule in our $routes array matches every request - using the
-wildcard operator (:any) - 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.
diff --git a/user_guide_src/source/tutorial/index.rst b/user_guide_src/source/tutorial/index.rst
index a0ed53c85..eb6f11e34 100644
--- a/user_guide_src/source/tutorial/index.rst
+++ b/user_guide_src/source/tutorial/index.rst
@@ -1,5 +1,6 @@
-Tutorial − Introduction
-=======================
+########
+Tutorial
+########
This tutorial is intended to introduce you to the CodeIgniter framework
and the basic principles of MVC architecture. It will show you how a
@@ -33,3 +34,14 @@ through the following pages:
further reading and other resources.
Enjoy your exploration of the CodeIgniter framework.
+
+.. toctree::
+ :glob:
+ :hidden:
+ :titlesonly:
+
+ index
+ static_pages
+ news_section
+ create_news_items
+ conclusion \ No newline at end of file
diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst
index d37c3408f..fe8e41607 100644
--- a/user_guide_src/source/tutorial/news_section.rst
+++ b/user_guide_src/source/tutorial/news_section.rst
@@ -1,5 +1,6 @@
-Tutorial − News section
-=======================
+############
+News section
+############
In the last section, we went over some basic concepts of the framework
by writing a class that includes static pages. We cleaned up the URI by
@@ -15,7 +16,7 @@ are the place where you retrieve, insert, and update information in your
database or other data stores. They represent your data.
Open up the application/models directory and create a new file called
-news\_model.php and add the following code. Make sure you've configured
+news_model.php and add the following code. Make sure you've configured
your database properly as described
`here <../database/configuration.html>`_.
diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst
index 3c95c8b25..0bbf51b1b 100644
--- a/user_guide_src/source/tutorial/static_pages.rst
+++ b/user_guide_src/source/tutorial/static_pages.rst
@@ -1,5 +1,6 @@
-Tutorial − Static pages
-=======================
+############
+Static pages
+############
**Note:** This tutorial assumes you've downloaded CodeIgniter and
`installed the framework <../installation/index.html>`_ in your
@@ -22,13 +23,22 @@ is all we will need to know.
Create a file at application/controllers/pages.php with the following
code.
-<?php class Pages extends CI\_Controller { public function view($page =
-'home') { } }
+::
+
+ <?php
+ class Pages extends CI_Controller {
+
+ public function view($page == 'home')
+ {
+
+ }
+
+ }
You have created a class named "pages", with a view method that accepts
one argument named $page. The pages class is extending the
-CI\_Controller class. This means that the new pages class can access the
-methods and variables defined in the CI\_Controller class
+CI_Controller class. This means that the new pages class can access the
+methods and variables defined in the CI_Controller class
(system/core/Controller.php).
The **controller is what will become the center of every request** to
@@ -44,8 +54,15 @@ our page footer and header.
Create the header at application/views/templates/header.php and add the
following code.
-CodeIgniter 2 Tutorial
-======================
+::
+
+ <html>
+ <head>
+ <title>CodeIgniter 2 Tutorial</title>
+ </head>
+ <body>
+
+ <h1>CodeIgniter 2 Tutorial<h1>
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
@@ -53,7 +70,11 @@ output the $title variable, which we'll define later in the controller.
Now create a footer at application/views/templates/footer.php that
includes the following code:
-**&copy; 2011**
+::
+
+ <em>&copy; 2011</em>
+ </body>
+ <html>
Adding logic to the controller
------------------------------
@@ -72,6 +93,7 @@ page actually exists:
::
+ <?php
public function view($page = 'home')
{