summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/tutorial
diff options
context:
space:
mode:
Diffstat (limited to 'user_guide_src/source/tutorial')
-rw-r--r--user_guide_src/source/tutorial/create_news_items.rst24
-rw-r--r--user_guide_src/source/tutorial/index.rst8
-rw-r--r--user_guide_src/source/tutorial/news_section.rst16
-rw-r--r--user_guide_src/source/tutorial/static_pages.rst109
4 files changed, 78 insertions, 79 deletions
diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst
index 1f4a96dd3..71d2080af 100644
--- a/user_guide_src/source/tutorial/create_news_items.rst
+++ b/user_guide_src/source/tutorial/create_news_items.rst
@@ -37,16 +37,16 @@ application/views/news/create.php.
There are only two things here that probably look unfamiliar to you: the
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
-adds extra functionality, like adding a hidden `CSRF prevention
-field <../libraries/security.html>`_. The latter is used to report
+The first function is provided by the :doc:`form
+helper <../helpers/form_helper>` and renders the form element and
+adds extra functionality, like adding a hidden :doc:`CSRF prevention
+field <../libraries/security>`. The latter is used to report
errors related to form validation.
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 <../libraries/form_validation.html>`_ library to do this.
+passed the validation rules. You'll use the :doc:`form
+validation <../libraries/form_validation>` library to do this.
::
@@ -81,14 +81,14 @@ the name of the input field, the name to be used in error messages, and
the rule. In this case the title and text fields are required.
CodeIgniter has a powerful form validation library as demonstrated
-above. You can read `more about this library
-here <../libraries/form_validation.html>`_.
+above. You can read :doc:`more about this library
+here <../libraries/form_validation>`.
Continuing down, you can see a condition that checks whether the form
validation ran successfully. If it did not, the form is displayed, if it
was submitted **and** passed all the rules, the model is called. After
this, a view is loaded to display a success message. Create a view at
-application/view/news/success.php and write a success message.
+application/views/news/success.php and write a success message.
Model
-----
@@ -117,7 +117,7 @@ the model created earlier and add the following:
This new method takes care of inserting the news item into the database.
The third line contains a new function, url\_title(). This function -
-provided by the `URL helper <../helpers/url_helper.html>`_ - strips down
+provided by the :doc:`URL helper <../helpers/url_helper>` - 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.
@@ -125,8 +125,8 @@ slug, perfect for creating URIs.
Let's continue with preparing the record that is going to be inserted
later, inside the $data array. Each element corresponds with a column in
the database table created earlier. You might notice a new method here,
-namely the post() method from the `input
-library <../libraries/input.html>`_. This method makes sure the data is
+namely the post() method from the :doc:`input
+library <../libraries/input>`. 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 $data array into
our database.
diff --git a/user_guide_src/source/tutorial/index.rst b/user_guide_src/source/tutorial/index.rst
index b1ab331d1..91f99c7cd 100644
--- a/user_guide_src/source/tutorial/index.rst
+++ b/user_guide_src/source/tutorial/index.rst
@@ -24,13 +24,13 @@ through the following pages:
- Introduction, this page, which gives you an overview of what to
expect.
-- `Static pages <static_pages.html>`_, which will teach you the basics
+- :doc:`Static pages <static_pages>`, which will teach you the basics
of controllers, views and routing.
-- `News section <news_section.html>`_, where you'll start using models
+- :doc:`News section <news_section>`, where you'll start using models
and will be doing some basic database operations.
-- `Create news items <create_news_items.html>`_, which will introduce
+- :doc:`Create news items <create_news_items>`, which will introduce
more advanced database operations and form validation.
-- `Conclusion <conclusion.html>`_, which will give you some pointers on
+- :doc:`Conclusion <conclusion>`, which will give you some pointers on
further reading and other resources.
Enjoy your exploration of the CodeIgniter framework.
diff --git a/user_guide_src/source/tutorial/news_section.rst b/user_guide_src/source/tutorial/news_section.rst
index 80938de32..d8ebac4a3 100644
--- a/user_guide_src/source/tutorial/news_section.rst
+++ b/user_guide_src/source/tutorial/news_section.rst
@@ -18,7 +18,7 @@ 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
your database properly as described
-`here <../database/configuration.html>`_.
+:doc:`here <../database/configuration>`.
::
@@ -53,10 +53,10 @@ seed records.
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 <../database/query_builder.html>`_ — is used. This makes it
-possible to write your 'queries' once and make them work on `all
-supported database systems <../general/requirements.html>`_. Add the
+abstraction layer that is included with CodeIgniter —
+:doc:`Query Builder <../database/query_builder>` — is used. This makes it
+possible to write your 'queries' once and make them work on :doc:`all
+supported database systems <../general/requirements>`. Add the
following code to your model.
::
@@ -151,14 +151,14 @@ and add the next piece of code.
<div class="main">
<?php echo $news_item['text'] ?>
</div>
- <p><a href="news/<?php echo $news_item['slug'] ?>">View article</a></p>
+ <p><a href="<?php echo $news_item['slug'] ?>">View article</a></p>
<?php endforeach ?>
Here, each news item is looped and displayed to the user. You can see we
wrote our template in PHP mixed with HTML. If you prefer to use a
-template language, you can use CodeIgniter's `Template
-Parser <../libraries/parser>`_ class or a third party parser.
+template language, you can use CodeIgniter's :doc:`Template
+Parser <../libraries/parser>` class or a third party parser.
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
diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst
index 36bcd2df9..62b3469ad 100644
--- a/user_guide_src/source/tutorial/static_pages.rst
+++ b/user_guide_src/source/tutorial/static_pages.rst
@@ -3,7 +3,7 @@ Static pages
############
**Note:** This tutorial assumes you've downloaded CodeIgniter and
-`installed the framework <../installation/index.html>`_ in your
+:doc:`installed the framework <../installation/index>` in your
development environment.
The first thing you're going to do is set up a **controller** to handle
@@ -11,12 +11,16 @@ static pages. A controller is simply a class that helps delegate work.
It is the glue of your web application.
For example, when a call is made to:
-``http://example.com/news/latest/10`` We might imagine that there is a
-controller named "news". The method being called on news would be
-"latest". The news method's job could be to grab 10 news items, and
-render them on the page. Very often in MVC, you'll see URL patterns that
-match:
-``http://example.com/[controller-class]/[controller-method]/[arguments]``
+
+ http://example.com/news/latest/10
+
+We might imagine that there is a controller named "news". The method
+being called on news would be "latest". The news method's job could be to
+grab 10 news items, and render them on the page. Very often in MVC,
+you'll see URL patterns that match:
+
+ http://example.com/[controller-class]/[controller-method]/[arguments]
+
As URL schemes become more complex, this may change. But for now, this
is all we will need to know.
@@ -25,15 +29,13 @@ code.
::
- <?php
- class Pages extends CI_Controller {
+ <?php
+ class Pages extends CI_Controller {
- public function view($page = 'home')
- {
-
- }
-
- }
+ 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
@@ -56,13 +58,13 @@ following code.
::
- <html>
- <head>
- <title>CodeIgniter Tutorial</title>
- </head>
- <body>
+ <html>
+ <head>
+ <title>CodeIgniter Tutorial</title>
+ </head>
+ <body>
- <h1>CodeIgniter Tutorial</h1>
+ <h1><?php echo $title ?></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
@@ -72,16 +74,16 @@ includes the following code:
::
- <em>&copy; 2014</em>
- </body>
- <html>
+ <em>&copy; 2014</em>
+ </body>
+ </html>
Adding logic to the controller
------------------------------
-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 application/views/pages/
+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 application/views/pages/
directory.
In that directory, create two files named home.php and about.php. Within
@@ -93,43 +95,40 @@ page actually exists:
::
- <?php
- public function view($page = 'home')
- {
-
- if ( ! file_exists(APPPATH.'/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);
-
- }
+ public function view($page = 'home')
+ {
+ if ( ! file_exists(APPPATH.'/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);
+ }
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.
The first line in this method checks whether the page actually exists.
-PHP's native file\_exists() function is used to check whether the file
-is where it's expected to be. show\_404() is a built-in CodeIgniter
+PHP's native ``file_exists()`` function is used to check whether the file
+is where it's expected to be. ``show_404()`` is a built-in CodeIgniter
function that renders the default error page.
-In the header template, the $title variable was used to customize the
+In the header template, the ``$title`` variable was used to customize the
page title. The value of title is defined in this method, but instead of
assigning the value to a variable, it is assigned to the title element
in the $data array.
The last thing that has to be done is loading the views in the order
-they should be displayed. The second parameter in the view() method is
-used to pass values to the view. Each value in the $data array is
+they should be displayed. The second parameter in the ``view()`` method is
+used to pass values to the view. Each value in the ``$data`` array is
assigned to a variable with the name of its key. So the value of
-$data['title'] in the controller is equivalent to $title in the view.
+``$data['title']`` in the controller is equivalent to $title in the view.
Routing
-------
@@ -149,8 +148,8 @@ all other code that sets any element in the $route array.
::
- $route['default_controller'] = 'pages/view';
- $route['(:any)'] = 'pages/view/$1';
+ $route['default_controller'] = 'pages/view';
+ $route['(:any)'] = 'pages/view/$1';
CodeIgniter reads its routing rules from top to bottom and routes the
request to the first matching rule. Each rule is a regular expression
@@ -160,11 +159,11 @@ match, and calls the appropriate controller and method, possibly with
arguments.
More information about routing can be found in the URI Routing
-`documentation <../general/routing.html>`_.
+:doc:`documentation <../general/routing>`.
Here, the second rule in the $routes array matches **any** request using
-the wildcard string (:any). and passes the parameter to the view()
+the wildcard string (:any). and passes the parameter to the ``view()``
method of the pages class.
-Now visit index.php/about. Did it get routed correctly to the view()
+Now visit index.php/about. Did it get routed correctly to the ``view()``
method in the pages controller? Awesome!