summaryrefslogtreecommitdiffstats
path: root/user_guide_src/source/tutorial/static_pages.rst
diff options
context:
space:
mode:
authorAndrey Andreev <narf@devilix.net>2015-05-21 14:13:47 +0200
committerAndrey Andreev <narf@devilix.net>2015-05-21 14:13:47 +0200
commit3a4f9cd467b23ca5aeb93d20214685c86c0d520c (patch)
tree7861a9c8d08789e050de39d152dd367d0328d611 /user_guide_src/source/tutorial/static_pages.rst
parentb8cd5e657363795f127ae5e02e69972627b3fe9c (diff)
[ci skip] Update tutorial
Related: #3866
Diffstat (limited to 'user_guide_src/source/tutorial/static_pages.rst')
-rw-r--r--user_guide_src/source/tutorial/static_pages.rst53
1 files changed, 27 insertions, 26 deletions
diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst
index e948d3011..66621471e 100644
--- a/user_guide_src/source/tutorial/static_pages.rst
+++ b/user_guide_src/source/tutorial/static_pages.rst
@@ -37,24 +37,24 @@ code.
}
}
-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
-(system/core/Controller.php).
+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
+(*system/core/Controller.php*).
The **controller is what will become the center of every request** to
your web application. In very technical CodeIgniter discussions, it may
be referred to as the *super object*. Like any php class, you refer to
-it within your controllers as $this. Referring to $this is how you will
-load libraries, views, and generally command the framework.
+it within your controllers as ``$this``. Referring to ``$this`` is how
+you will load libraries, views, and generally command the framework.
Now you've created your first method, it's time to make some basic page
templates. We will be creating two "views" (page templates) that act as
our page footer and header.
-Create the header at application/views/templates/header.php and add the
-following code.
+Create the header at *application/views/templates/header.php* and add
+the following code:
::
@@ -68,13 +68,13 @@ following code.
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 $title variable, which we'll define later in the controller.
-Now create a footer at application/views/templates/footer.php that
+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:
::
- <em>&copy; 2014</em>
+ <em>&copy; 2015</em>
</body>
</html>
@@ -83,12 +83,12 @@ 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/
+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
-those files, type some text − anything you'd like − and save them. If
-you like to be particularly un-original, try "Hello World!".
+In that directory, create two files named *home.php* and *about.php*.
+Within those files, type some text − anything you'd like − and save them.
+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:
@@ -122,20 +122,21 @@ function that renders the default error page.
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.
+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
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
-------
The controller is now functioning! Point your browser to
-[your-site-url]index.php/pages/view to see your page. When you visit
-index.php/pages/view/about you'll see the about page, again including
+``[your-site-url]index.php/pages/view`` to see your page. When you visit
+``index.php/pages/view/about`` you'll see the about page, again including
the header and footer.
Using custom routing rules, you have the power to map any URI to any
@@ -143,8 +144,8 @@ controller and method, and break free from the normal convention:
``http://example.com/[controller-class]/[controller-method]/[arguments]``
Let's do that. 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.
+*application/config/routes.php* and add the following two lines.
+Remove all other code that sets any element in the ``$route`` array.
::
@@ -161,9 +162,9 @@ arguments.
More information about routing can be found in the URI Routing
: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()``
-method of the pages class.
+Here, the second rule in the ``$routes`` array matches **any** request
+using 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!