From c5f99fdcc5c4a918b5b8fe3ddbd56ab25ad1c22b Mon Sep 17 00:00:00 2001 From: Wes Baker Date: Mon, 8 Jul 2013 17:22:21 -0400 Subject: Updating User Guide for 2.1.4. --- user_guide/tutorial/hard_coded_pages.html | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'user_guide/tutorial/hard_coded_pages.html') 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 @@
- +

CodeIgniter User Guide Version 2.1.3

CodeIgniter User Guide Version Location

@@ -86,13 +86,13 @@ class Pages extends CI_Controller {

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.

- + @@ -106,36 +106,36 @@ class Pages extends CI_Controller {

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.

- +

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.

- + -

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.

+

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.

-- cgit v1.2.3-24-g4f1b