From f4fb1db458fab52d0493ead52c9ea7e01206eaa7 Mon Sep 17 00:00:00 2001 From: Joël Cox Date: Sun, 9 Oct 2011 18:39:39 +0200 Subject: Moved tutorial to new user guide directory. --- user_guide_src/source/tutorial/conclusion.html | 91 ++++++++ .../source/tutorial/create_news_items.html | 179 ++++++++++++++++ .../source/tutorial/hard_coded_pages.html | 158 ++++++++++++++ user_guide_src/source/tutorial/index.html | 101 +++++++++ user_guide_src/source/tutorial/news_section.html | 230 +++++++++++++++++++++ user_guide_src/source/tutorial/static_pages.html | 206 ++++++++++++++++++ 6 files changed, 965 insertions(+) create mode 100644 user_guide_src/source/tutorial/conclusion.html create mode 100644 user_guide_src/source/tutorial/create_news_items.html create mode 100644 user_guide_src/source/tutorial/hard_coded_pages.html create mode 100644 user_guide_src/source/tutorial/index.html create mode 100644 user_guide_src/source/tutorial/news_section.html create mode 100644 user_guide_src/source/tutorial/static_pages.html (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/tutorial/conclusion.html b/user_guide_src/source/tutorial/conclusion.html new file mode 100644 index 000000000..ccf89175f --- /dev/null +++ b/user_guide_src/source/tutorial/conclusion.html @@ -0,0 +1,91 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial - 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 more important topics of routing, writing controllers, and models. We hope this tutorial gave you an insight into some of CodeIgniter's basic design patterns, which you can expand upon.

+ +

Now that you've completed this tutorial, we recommend you check out the rest of the documentation. CodeIgniter is often praised because of its comprehensive documentation. Use this to your advantage and read the "Introduction" and "General Topics" sections thoroughly. You should read the class and helper references when needed.

+ +

Every intermediate PHP programmer should be able to get the hang of CodeIgniter within a few days.

+ +

If you still have questions about the framework or your own CodeIgniter code, you can:

+ + +
+ + + + + + + \ No newline at end of file diff --git a/user_guide_src/source/tutorial/create_news_items.html b/user_guide_src/source/tutorial/create_news_items.html new file mode 100644 index 000000000..48c82c799 --- /dev/null +++ b/user_guide_src/source/tutorial/create_news_items.html @@ -0,0 +1,179 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial - 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 you'll expand your news controller and model created earlier to include this functionality.

+ +

Create a form

+ +

To input data into the database you need to create a form where you can input the information to be stored. This means you'll be needing a form 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.

+ + + +

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 and renders the form element and adds extra functionality, like adding a hidden CSFR prevention field. 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 library to do this.

+ +
+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('news/create');
+		$this->load->view('templates/footer');
+		
+	}
+	else
+	{
+		$this->news_model->set_news();
+		$this->load->view('news/success');
+	}
+}
+
+ +

The code above adds a lot of functionality. The first few lines load the form helper and the form validation library. After that, rules for the form validation are set. The set_rules() method takes three arguments; 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.

+ +

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.

+ +

Model

+ +

The only thing that remains is writing a method that writes the data to the database. You'll use the Active Record class to insert the information and use the input library to get the posted data. Open up the model created earlier and add the following:

+ +
+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);
+}
+
+ +

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 - 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.

+ +

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. 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.

+ +

Routing

+ +

Before you can start adding news items into your CodeIgniter application you have to add an extra rule to config/routes.php file. Make sure your file contains the following. This makes sure CodeIgniter sees 'create' as a method instead of a news item's slug.

+ +
+$route['news/create'] = 'news/create';
+$route['news/(:any)'] = 'news/view/$1';
+$route['news'] = 'news';
+$route['(:any)'] = 'pages/view/$1';
+$route['default_controller'] = 'pages/view';
+
+ +

Now point your browser to your local development environment where you installed CodeIgniter and add index.php/news/create to the URL. Congratulations, you just created your first CodeIgniter application! Add some news and check out the different pages you made.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide_src/source/tutorial/hard_coded_pages.html b/user_guide_src/source/tutorial/hard_coded_pages.html new file mode 100644 index 000000000..408634a78 --- /dev/null +++ b/user_guide_src/source/tutorial/hard_coded_pages.html @@ -0,0 +1,158 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial - Hard coded pages

+ +

The first thing we're going to do is setting up a controller to handle our hard coded pages. A controller is a class with a collection of methods that represent the different actions you can perform on a certain object. In our case, we want to be able to view a page.

+ +

Note: This tutorial assumes you've downloaded CodeIgniter and installed the framework in your development environment.

+ +

Create a file at application/controllers/pages.php with the following code.

+ + + +

If you're familiar with PHP classes you see that we create a Pages class with a view method that accepts one parameter, $page. Another interesting observation is that 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. When you look at this class in system/core/controller.php you can see this class is doing something really important; assigning an instance from the CodeIgniter super object to the $this object. In most of your code, $this is the object you will use to interact with the framework.

+ +

Now we've created our first method, it is time to do some basic templating. For this tutorial, we will be creating two views to acts as our footer and header. Let's create our header at application/views/templates/header.php and ad the following code.

+ + + +

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.

+ + + +

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.

+ + + +

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.

+ + + +

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.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide_src/source/tutorial/index.html b/user_guide_src/source/tutorial/index.html new file mode 100644 index 000000000..4f665fe0a --- /dev/null +++ b/user_guide_src/source/tutorial/index.html @@ -0,0 +1,101 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial − Introduction

+ +

This tutorial is intended to introduce you to the CodeIgniter framework and the basic principles of MVC architecture. It will show you how a basic CodeIgniter application is constructed in step-by-step fashion.

+ +

In this tutorial, you will be creating a basic news application. You will begin by writing the code that can load static pages. Next, you will create a news section that reads news items from a database. Finally, you'll add a form to create news items in the database.

+ +

This tutorial will primarily focus on:

+ + +

The entire tutorial is split up over several pages, each explaining a small part of the functionality of the CodeIgniter framework. You'll go through the following pages:

+ + +

Enjoy your exploration of the CodeIgniter framework.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide_src/source/tutorial/news_section.html b/user_guide_src/source/tutorial/news_section.html new file mode 100644 index 000000000..b2d883184 --- /dev/null +++ b/user_guide_src/source/tutorial/news_section.html @@ -0,0 +1,230 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial − 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 adding custom routing rules. Now it's time to introduce dynamic content and start using a database.

+ +

Setting up your model

+ +

Instead of writing database operations right in the controller, queries should be placed in a model, so they can easily be reused later. Models 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 your database properly as described here.

+ +
+<?php
+class News_model extends CI_Model {
+
+	public function __construct()
+	{
+		$this->load->database();
+	}
+}
+
+ +

This code looks similar to the controller code that was used earlier. It creates a new model by extending CI_Model and loads the database library. This will make the database class available through the $this->db object.

+ +

Before querying the database, a database schema has to be created. Connect to your database and run the SQL command below. Also add some seed records.

+ +
+CREATE TABLE news (
+	id int(11) NOT NULL AUTO_INCREMENT,
+	title varchar(128) NOT NULL,
+	slug varchar(128) NOT NULL,
+	text text NOT NULL,
+	PRIMARY KEY (id),
+	KEY slug (slug)
+);
+
+ +

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 — is used. This makes it possible to write your 'queries' once and make them work on all supported database systems. Add the following code to your model.

+ +
+public function get_news($slug = FALSE)
+{
+	if ($slug === FALSE)
+	{
+		$query = $this->db->get('news');
+		return $query->result_array();
+	}
+	
+	$query = $this->db->get_where('news', array('slug' => $slug));
+	return $query->row_array();
+}
+
+ +

With this code you can perform two different queries. You can get all news records, or get a news item by its slug. You might have noticed that the $slug variable wasn't sanitized before running the query; Active Record does this for you.

+ +

Display the news

+ +

Now that the queries are written, the model should be tied to the views that are going to display the news items to the user. This could be done in our pages controller created earlier, but for the sake of clarity, a new "news" controller is defined. Create the new controller at application/controllers/news.php.

+ +
+<?php
+class News extends CI_Controller {
+
+	public function __construct()
+	{
+		parent::__construct();
+		$this->load->model('news_model');
+	}
+
+	public function index()
+	{
+		$data['news'] = $this->news_model->get_news();
+	}
+
+	public function view($slug)
+	{
+		$data['news'] = $this->news_model->get_news($slug);
+	}
+}
+
+ +

Looking at the code, you may see some similarity with the files we created earlier. First, the "__construct" method: it calls the constructor of its parent class (CI_Controller) and loads the model, so it can be used in all other methods in this controller.

+ +

Next, there are two methods to view all news items and one for a specific news item. You can see that the $slug variable is passed to the model's method in the second method. The model is using this slug to identify the news item to be returned.

+ +

Now the data is retrieved by the controller through our model, but nothing is displayed yet. The next thing to do is passing this data to the views.

+ +
+public function index()
+{
+	$data['news'] = $this->news_model->get_news();
+	$data['title'] = 'News archive';
+
+	$this->load->view('templates/header', $data);
+	$this->load->view('news/index', $data);
+	$this->load->view('templates/footer');
+}
+
+ +

The code above gets all news records from the model and assigns it to a variable. The value for the title is also assigned to the $data['title'] element and all data is passed to the views. You now need to create a view to render the news items. Create application/views/news/index.php and add the next piece of code.

+ +
+<?php foreach ($news as $news_item): ?>
+
+    <h2><?php echo $news_item['title'] ?></h2>
+    <div id="main">
+        <?php echo $news_item['text'] ?>
+    </div>
+    <p><a href="news/<?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 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 way that it can easily be used for this functionality. You only need to add some code to the controller and create a new view. Go back to the news controller and add the following lines to the file.

+ +
+public function view($slug)
+{
+	$data['news_item'] = $this->news_model->get_news($slug);
+
+	if (empty($data['news_item']))
+	{
+		show_404();
+	}
+
+	$data['title'] = $data['news_item']['title'];
+
+	$this->load->view('templates/header', $data);
+	$this->load->view('news/view', $data);
+	$this->load->view('templates/footer');
+}
+
+ +

Instead of calling the get_news() method without a parameter, the $slug variable is passed, so it will return the specific news item. The only things left to do is create the corresponding view at application/views/news/view.php. Put the following code in this file.

+ +
+<?php
+echo '<h2>'.$news_item['title'].'</h2>';
+echo $news_item['text'];
+
+ +

Routing

+

Because of the wildcard routing rule created earlier, you need need an extra route to view the controller that you just made. Modify your routing file (application/config/routes.php) so it looks as follows. This makes sure the requests reaches the news controller instead of going directly to the pages controller. The first line routes URI's with a slug to the view method in the news controller.

+ +
+$route['news/(:any)'] = 'news/view/$1';
+$route['news'] = 'news';
+$route['(:any)'] = 'pages/view/$1';
+$route['default_controller'] = 'pages/view';
+
+ +

Point your browser to your document root, followed by index.php/news and watch your news page.

+ +
+ + + + + + + \ No newline at end of file diff --git a/user_guide_src/source/tutorial/static_pages.html b/user_guide_src/source/tutorial/static_pages.html new file mode 100644 index 000000000..26c8306e1 --- /dev/null +++ b/user_guide_src/source/tutorial/static_pages.html @@ -0,0 +1,206 @@ + + + + + +CodeIgniter Features : CodeIgniter User Guide + + + + + + + + + + + + + + + + + + + + + +
+ + + + + +

CodeIgniter User Guide Version 2.0.3

+
+ + + + + + + + + +
+ + +
+ + + +
+ + +

Tutorial − Static pages

+ +

Note: This tutorial assumes you've downloaded CodeIgniter and installed the framework in your development environment.

+ +

The first thing you're going to do is set up a controller to handle 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] +As URL schemes become more complex, this may change. But for now, this is all we will need to know.

+ +

Create a file at application/controllers/pages.php with the following 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).

+ +

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.

+ +

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.

+ + + +

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 includes the following code:

+ + + +

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/ 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 order to load those pages, you'll have to check whether the requested page actually exists:

+ +
+public function view($page = 'home')
+{
+			
+	if ( ! file_exists('application/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 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.

+ +

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.

+ +

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 the header and footer.

+ +

Using custom routing rules, you have the power to map any URI to any 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.

+ +
+$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 +(left-side) mapped to a controller and method name separated by slashes (right-side). +When a request comes in, CodeIgniter looks for the first match, and calls the appropriate controller and method, possibly with arguments.

+ +

More information about routing can be found in the URI Routing documentation.

+ +

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() method +in the pages controller? Awesome!

+ +
+ + + + + + + \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 3bf17fb1423283d79a81b6ec3ca6134566b28475 Mon Sep 17 00:00:00 2001 From: Joël Cox Date: Sun, 9 Oct 2011 19:20:12 +0200 Subject: Initial conversion of the HTML to RST using pandoc. --- user_guide_src/source/tutorial/conclusion.html | 91 -------- user_guide_src/source/tutorial/conclusion.rst | 25 +++ .../source/tutorial/create_news_items.html | 179 ---------------- .../source/tutorial/create_news_items.rst | 142 +++++++++++++ .../source/tutorial/hard_coded_pages.html | 158 -------------- .../source/tutorial/hard_coded_pages.rst | 73 +++++++ user_guide_src/source/tutorial/index.html | 101 --------- user_guide_src/source/tutorial/index.rst | 35 ++++ user_guide_src/source/tutorial/news_section.html | 230 --------------------- user_guide_src/source/tutorial/news_section.rst | 213 +++++++++++++++++++ user_guide_src/source/tutorial/static_pages.html | 206 ------------------ user_guide_src/source/tutorial/static_pages.rst | 148 +++++++++++++ 12 files changed, 636 insertions(+), 965 deletions(-) delete mode 100644 user_guide_src/source/tutorial/conclusion.html create mode 100644 user_guide_src/source/tutorial/conclusion.rst delete mode 100644 user_guide_src/source/tutorial/create_news_items.html create mode 100644 user_guide_src/source/tutorial/create_news_items.rst delete mode 100644 user_guide_src/source/tutorial/hard_coded_pages.html create mode 100644 user_guide_src/source/tutorial/hard_coded_pages.rst delete mode 100644 user_guide_src/source/tutorial/index.html create mode 100644 user_guide_src/source/tutorial/index.rst delete mode 100644 user_guide_src/source/tutorial/news_section.html create mode 100644 user_guide_src/source/tutorial/news_section.rst delete mode 100644 user_guide_src/source/tutorial/static_pages.html create mode 100644 user_guide_src/source/tutorial/static_pages.rst (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/tutorial/conclusion.html b/user_guide_src/source/tutorial/conclusion.html deleted file mode 100644 index ccf89175f..000000000 --- a/user_guide_src/source/tutorial/conclusion.html +++ /dev/null @@ -1,91 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial - 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 more important topics of routing, writing controllers, and models. We hope this tutorial gave you an insight into some of CodeIgniter's basic design patterns, which you can expand upon.

- -

Now that you've completed this tutorial, we recommend you check out the rest of the documentation. CodeIgniter is often praised because of its comprehensive documentation. Use this to your advantage and read the "Introduction" and "General Topics" sections thoroughly. You should read the class and helper references when needed.

- -

Every intermediate PHP programmer should be able to get the hang of CodeIgniter within a few days.

- -

If you still have questions about the framework or your own CodeIgniter code, you can:

- - -
- - - - - - - \ No newline at end of file diff --git a/user_guide_src/source/tutorial/conclusion.rst b/user_guide_src/source/tutorial/conclusion.rst new file mode 100644 index 000000000..3b193d63d --- /dev/null +++ b/user_guide_src/source/tutorial/conclusion.rst @@ -0,0 +1,25 @@ +Tutorial - 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 +more important topics of routing, writing controllers, and models. We +hope this tutorial gave you an insight into some of CodeIgniter's basic +design patterns, which you can expand upon. + +Now that you've completed this tutorial, we recommend you check out the +rest of the documentation. CodeIgniter is often praised because of its +comprehensive documentation. Use this to your advantage and read the +"Introduction" and "General Topics" sections thoroughly. You should read +the class and helper references when needed. + +Every intermediate PHP programmer should be able to get the hang of +CodeIgniter within a few days. + +If you still have questions about the framework or your own CodeIgniter +code, you can: + +- Check out our `forums `_ +- Visit our `IRC chatroom `_ +- Explore the `Wiki `_ + diff --git a/user_guide_src/source/tutorial/create_news_items.html b/user_guide_src/source/tutorial/create_news_items.html deleted file mode 100644 index 48c82c799..000000000 --- a/user_guide_src/source/tutorial/create_news_items.html +++ /dev/null @@ -1,179 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial - 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 you'll expand your news controller and model created earlier to include this functionality.

- -

Create a form

- -

To input data into the database you need to create a form where you can input the information to be stored. This means you'll be needing a form 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.

- - - -

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 and renders the form element and adds extra functionality, like adding a hidden CSFR prevention field. 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 library to do this.

- -
-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('news/create');
-		$this->load->view('templates/footer');
-		
-	}
-	else
-	{
-		$this->news_model->set_news();
-		$this->load->view('news/success');
-	}
-}
-
- -

The code above adds a lot of functionality. The first few lines load the form helper and the form validation library. After that, rules for the form validation are set. The set_rules() method takes three arguments; 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.

- -

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.

- -

Model

- -

The only thing that remains is writing a method that writes the data to the database. You'll use the Active Record class to insert the information and use the input library to get the posted data. Open up the model created earlier and add the following:

- -
-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);
-}
-
- -

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 - 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.

- -

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. 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.

- -

Routing

- -

Before you can start adding news items into your CodeIgniter application you have to add an extra rule to config/routes.php file. Make sure your file contains the following. This makes sure CodeIgniter sees 'create' as a method instead of a news item's slug.

- -
-$route['news/create'] = 'news/create';
-$route['news/(:any)'] = 'news/view/$1';
-$route['news'] = 'news';
-$route['(:any)'] = 'pages/view/$1';
-$route['default_controller'] = 'pages/view';
-
- -

Now point your browser to your local development environment where you installed CodeIgniter and add index.php/news/create to the URL. Congratulations, you just created your first CodeIgniter application! Add some news and check out the different pages you made.

- -
- - - - - - - \ No newline at end of file diff --git a/user_guide_src/source/tutorial/create_news_items.rst b/user_guide_src/source/tutorial/create_news_items.rst new file mode 100644 index 000000000..4a0056ada --- /dev/null +++ b/user_guide_src/source/tutorial/create_news_items.rst @@ -0,0 +1,142 @@ +Tutorial - 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 +you'll expand your news controller and model created earlier to include +this functionality. + +Create a form +------------- + +To input data into the database you need to create a form where you can +input the information to be stored. This means you'll be needing a form +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 +------------------ + + Title + Text + + +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 `CSFR prevention +field <../libraries/security.html>`_. 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. + +:: + + 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('news/create'); + $this->load->view('templates/footer'); + + } + else + { + $this->news_model->set_news(); + $this->load->view('news/success'); + } + } + +The code above adds a lot of functionality. The first few lines load the +form helper and the form validation library. After that, rules for the +form validation are set. The set\_rules() method takes three arguments; +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>`_. + +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. + +Model +----- + +The only thing that remains is writing a method that writes the data to +the database. You'll use the Active Record class to insert the +information and use the input library to get the posted data. Open up +the model created earlier and add the following: + +:: + + 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); + } + +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 +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. + +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 +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. + +Routing +------- + +Before you can start adding news items into your CodeIgniter application +you have to add an extra rule to config/routes.php file. Make sure your +file contains the following. This makes sure CodeIgniter sees 'create' +as a method instead of a news item's slug. + +:: + + $route['news/create'] = 'news/create'; + $route['news/(:any)'] = 'news/view/$1'; + $route['news'] = 'news'; + $route['(:any)'] = 'pages/view/$1'; + $route['default_controller'] = 'pages/view'; + +Now point your browser to your local development environment where you +installed CodeIgniter and add index.php/news/create to the URL. +Congratulations, you just created your first CodeIgniter application! +Add some news and check out the different pages you made. diff --git a/user_guide_src/source/tutorial/hard_coded_pages.html b/user_guide_src/source/tutorial/hard_coded_pages.html deleted file mode 100644 index 408634a78..000000000 --- a/user_guide_src/source/tutorial/hard_coded_pages.html +++ /dev/null @@ -1,158 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial - Hard coded pages

- -

The first thing we're going to do is setting up a controller to handle our hard coded pages. A controller is a class with a collection of methods that represent the different actions you can perform on a certain object. In our case, we want to be able to view a page.

- -

Note: This tutorial assumes you've downloaded CodeIgniter and installed the framework in your development environment.

- -

Create a file at application/controllers/pages.php with the following code.

- - - -

If you're familiar with PHP classes you see that we create a Pages class with a view method that accepts one parameter, $page. Another interesting observation is that 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. When you look at this class in system/core/controller.php you can see this class is doing something really important; assigning an instance from the CodeIgniter super object to the $this object. In most of your code, $this is the object you will use to interact with the framework.

- -

Now we've created our first method, it is time to do some basic templating. For this tutorial, we will be creating two views to acts as our footer and header. Let's create our header at application/views/templates/header.php and ad the following code.

- - - -

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.

- - - -

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.

- - - -

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.

- - - -

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.

- -
- - - - - - - \ No newline at end of file diff --git a/user_guide_src/source/tutorial/hard_coded_pages.rst b/user_guide_src/source/tutorial/hard_coded_pages.rst new file mode 100644 index 000000000..c7b541768 --- /dev/null +++ b/user_guide_src/source/tutorial/hard_coded_pages.rst @@ -0,0 +1,73 @@ +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.html b/user_guide_src/source/tutorial/index.html deleted file mode 100644 index 4f665fe0a..000000000 --- a/user_guide_src/source/tutorial/index.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial − Introduction

- -

This tutorial is intended to introduce you to the CodeIgniter framework and the basic principles of MVC architecture. It will show you how a basic CodeIgniter application is constructed in step-by-step fashion.

- -

In this tutorial, you will be creating a basic news application. You will begin by writing the code that can load static pages. Next, you will create a news section that reads news items from a database. Finally, you'll add a form to create news items in the database.

- -

This tutorial will primarily focus on:

-
    -
  • Model-View-Controller basics
  • -
  • Routing basics
  • -
  • Form validation
  • -
  • Performing basic database queries using "Active Record"
  • -
- -

The entire tutorial is split up over several pages, each explaining a small part of the functionality of the CodeIgniter framework. You'll go through the following pages:

-
    -
  • Introduction, this page, which gives you an overview of what to expect.
  • -
  • Static pages, which will teach you the basics of controllers, views and routing.
  • -
  • News section, where you'll start using models and will be doing some basic database operations.
  • -
  • Create news items, which will introduce more advanced database operations and form validation.
  • -
  • Conclusion, which will give you some pointers on further reading and other resources.
  • -
- -

Enjoy your exploration of the CodeIgniter framework.

- -
- - - - - - - \ No newline at end of file diff --git a/user_guide_src/source/tutorial/index.rst b/user_guide_src/source/tutorial/index.rst new file mode 100644 index 000000000..a0ed53c85 --- /dev/null +++ b/user_guide_src/source/tutorial/index.rst @@ -0,0 +1,35 @@ +Tutorial − Introduction +======================= + +This tutorial is intended to introduce you to the CodeIgniter framework +and the basic principles of MVC architecture. It will show you how a +basic CodeIgniter application is constructed in step-by-step fashion. + +In this tutorial, you will be creating a **basic news application**. You +will begin by writing the code that can load static pages. Next, you +will create a news section that reads news items from a database. +Finally, you'll add a form to create news items in the database. + +This tutorial will primarily focus on: + +- Model-View-Controller basics +- Routing basics +- Form validation +- Performing basic database queries using "Active Record" + +The entire tutorial is split up over several pages, each explaining a +small part of the functionality of the CodeIgniter framework. You'll go +through the following pages: + +- Introduction, this page, which gives you an overview of what to + expect. +- `Static pages `_, which will teach you the basics + of controllers, views and routing. +- `News section `_, where you'll start using models + and will be doing some basic database operations. +- `Create news items `_, which will introduce + more advanced database operations and form validation. +- `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.html b/user_guide_src/source/tutorial/news_section.html deleted file mode 100644 index b2d883184..000000000 --- a/user_guide_src/source/tutorial/news_section.html +++ /dev/null @@ -1,230 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial − 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 adding custom routing rules. Now it's time to introduce dynamic content and start using a database.

- -

Setting up your model

- -

Instead of writing database operations right in the controller, queries should be placed in a model, so they can easily be reused later. Models 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 your database properly as described here.

- -
-<?php
-class News_model extends CI_Model {
-
-	public function __construct()
-	{
-		$this->load->database();
-	}
-}
-
- -

This code looks similar to the controller code that was used earlier. It creates a new model by extending CI_Model and loads the database library. This will make the database class available through the $this->db object.

- -

Before querying the database, a database schema has to be created. Connect to your database and run the SQL command below. Also add some seed records.

- -
-CREATE TABLE news (
-	id int(11) NOT NULL AUTO_INCREMENT,
-	title varchar(128) NOT NULL,
-	slug varchar(128) NOT NULL,
-	text text NOT NULL,
-	PRIMARY KEY (id),
-	KEY slug (slug)
-);
-
- -

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 — is used. This makes it possible to write your 'queries' once and make them work on all supported database systems. Add the following code to your model.

- -
-public function get_news($slug = FALSE)
-{
-	if ($slug === FALSE)
-	{
-		$query = $this->db->get('news');
-		return $query->result_array();
-	}
-	
-	$query = $this->db->get_where('news', array('slug' => $slug));
-	return $query->row_array();
-}
-
- -

With this code you can perform two different queries. You can get all news records, or get a news item by its slug. You might have noticed that the $slug variable wasn't sanitized before running the query; Active Record does this for you.

- -

Display the news

- -

Now that the queries are written, the model should be tied to the views that are going to display the news items to the user. This could be done in our pages controller created earlier, but for the sake of clarity, a new "news" controller is defined. Create the new controller at application/controllers/news.php.

- -
-<?php
-class News extends CI_Controller {
-
-	public function __construct()
-	{
-		parent::__construct();
-		$this->load->model('news_model');
-	}
-
-	public function index()
-	{
-		$data['news'] = $this->news_model->get_news();
-	}
-
-	public function view($slug)
-	{
-		$data['news'] = $this->news_model->get_news($slug);
-	}
-}
-
- -

Looking at the code, you may see some similarity with the files we created earlier. First, the "__construct" method: it calls the constructor of its parent class (CI_Controller) and loads the model, so it can be used in all other methods in this controller.

- -

Next, there are two methods to view all news items and one for a specific news item. You can see that the $slug variable is passed to the model's method in the second method. The model is using this slug to identify the news item to be returned.

- -

Now the data is retrieved by the controller through our model, but nothing is displayed yet. The next thing to do is passing this data to the views.

- -
-public function index()
-{
-	$data['news'] = $this->news_model->get_news();
-	$data['title'] = 'News archive';
-
-	$this->load->view('templates/header', $data);
-	$this->load->view('news/index', $data);
-	$this->load->view('templates/footer');
-}
-
- -

The code above gets all news records from the model and assigns it to a variable. The value for the title is also assigned to the $data['title'] element and all data is passed to the views. You now need to create a view to render the news items. Create application/views/news/index.php and add the next piece of code.

- -
-<?php foreach ($news as $news_item): ?>
-
-    <h2><?php echo $news_item['title'] ?></h2>
-    <div id="main">
-        <?php echo $news_item['text'] ?>
-    </div>
-    <p><a href="news/<?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 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 way that it can easily be used for this functionality. You only need to add some code to the controller and create a new view. Go back to the news controller and add the following lines to the file.

- -
-public function view($slug)
-{
-	$data['news_item'] = $this->news_model->get_news($slug);
-
-	if (empty($data['news_item']))
-	{
-		show_404();
-	}
-
-	$data['title'] = $data['news_item']['title'];
-
-	$this->load->view('templates/header', $data);
-	$this->load->view('news/view', $data);
-	$this->load->view('templates/footer');
-}
-
- -

Instead of calling the get_news() method without a parameter, the $slug variable is passed, so it will return the specific news item. The only things left to do is create the corresponding view at application/views/news/view.php. Put the following code in this file.

- -
-<?php
-echo '<h2>'.$news_item['title'].'</h2>';
-echo $news_item['text'];
-
- -

Routing

-

Because of the wildcard routing rule created earlier, you need need an extra route to view the controller that you just made. Modify your routing file (application/config/routes.php) so it looks as follows. This makes sure the requests reaches the news controller instead of going directly to the pages controller. The first line routes URI's with a slug to the view method in the news controller.

- -
-$route['news/(:any)'] = 'news/view/$1';
-$route['news'] = 'news';
-$route['(:any)'] = 'pages/view/$1';
-$route['default_controller'] = 'pages/view';
-
- -

Point your browser to your document root, followed by index.php/news and watch your news page.

- -
- - - - - - - \ 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 new file mode 100644 index 000000000..d37c3408f --- /dev/null +++ b/user_guide_src/source/tutorial/news_section.rst @@ -0,0 +1,213 @@ +Tutorial − 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 +adding custom routing rules. Now it's time to introduce dynamic content +and start using a database. + +Setting up your model +--------------------- + +Instead of writing database operations right in the controller, queries +should be placed in a model, so they can easily be reused later. Models +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 +your database properly as described +`here <../database/configuration.html>`_. + +:: + + load->database(); + } + } + +This code looks similar to the controller code that was used earlier. It +creates a new model by extending CI\_Model and loads the database +library. This will make the database class available through the +$this->db object. + +Before querying the database, a database schema has to be created. +Connect to your database and run the SQL command below. Also add some +seed records. + +:: + + CREATE TABLE news ( + id int(11) NOT NULL AUTO_INCREMENT, + title varchar(128) NOT NULL, + slug varchar(128) NOT NULL, + text text NOT NULL, + PRIMARY KEY (id), + KEY slug (slug) + ); + +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/active_record.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 +following code to your model. + +:: + + public function get_news($slug = FALSE) + { + if ($slug === FALSE) + { + $query = $this->db->get('news'); + return $query->result_array(); + } + + $query = $this->db->get_where('news', array('slug' => $slug)); + return $query->row_array(); + } + +With this code you can perform two different queries. You can get all +news records, or get a news item by its `slug <#>`_. You might have +noticed that the $slug variable wasn't sanitized before running the +query; Active Record does this for you. + +Display the news +---------------- + +Now that the queries are written, the model should be tied to the views +that are going to display the news items to the user. This could be done +in our pages controller created earlier, but for the sake of clarity, a +new "news" controller is defined. Create the new controller at +application/controllers/news.php. + +:: + + load->model('news_model'); + } + + public function index() + { + $data['news'] = $this->news_model->get_news(); + } + + public function view($slug) + { + $data['news'] = $this->news_model->get_news($slug); + } + } + +Looking at the code, you may see some similarity with the files we +created earlier. First, the "\_\_construct" method: it calls the +constructor of its parent class (CI\_Controller) and loads the model, so +it can be used in all other methods in this controller. + +Next, there are two methods to view all news items and one for a +specific news item. You can see that the $slug variable is passed to the +model's method in the second method. The model is using this slug to +identify the news item to be returned. + +Now the data is retrieved by the controller through our model, but +nothing is displayed yet. The next thing to do is passing this data to +the views. + +:: + + public function index() + { + $data['news'] = $this->news_model->get_news(); + $data['title'] = 'News archive'; + + $this->load->view('templates/header', $data); + $this->load->view('news/index', $data); + $this->load->view('templates/footer'); + } + +The code above gets all news records from the model and assigns it to a +variable. The value for the title is also assigned to the $data['title'] +element and all data is passed to the views. You now need to create a +view to render the news items. Create application/views/news/index.php +and add the next piece of code. + +:: + + + +

+
+ +
+

View article

+ + + +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.html>`_ 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 +way that it can easily be used for this functionality. You only need to +add some code to the controller and create a new view. Go back to the +news controller and add the following lines to the file. + +:: + + public function view($slug) + { + $data['news_item'] = $this->news_model->get_news($slug); + + if (empty($data['news_item'])) + { + show_404(); + } + + $data['title'] = $data['news_item']['title']; + + $this->load->view('templates/header', $data); + $this->load->view('news/view', $data); + $this->load->view('templates/footer'); + } + +Instead of calling the get\_news() method without a parameter, the $slug +variable is passed, so it will return the specific news item. The only +things left to do is create the corresponding view at +application/views/news/view.php. Put the following code in this file. + +:: + + '.$news_item['title'].''; + echo $news_item['text']; + +Routing +------- + +Because of the wildcard routing rule created earlier, you need need an +extra route to view the controller that you just made. Modify your +routing file (application/config/routes.php) so it looks as follows. +This makes sure the requests reaches the news controller instead of +going directly to the pages controller. The first line routes URI's with +a slug to the view method in the news controller. + +:: + + $route['news/(:any)'] = 'news/view/$1'; + $route['news'] = 'news'; + $route['(:any)'] = 'pages/view/$1'; + $route['default_controller'] = 'pages/view'; + +Point your browser to your document root, followed by index.php/news and +watch your news page. diff --git a/user_guide_src/source/tutorial/static_pages.html b/user_guide_src/source/tutorial/static_pages.html deleted file mode 100644 index 26c8306e1..000000000 --- a/user_guide_src/source/tutorial/static_pages.html +++ /dev/null @@ -1,206 +0,0 @@ - - - - - -CodeIgniter Features : CodeIgniter User Guide - - - - - - - - - - - - - - - - - - - - - -
- - - - - -

CodeIgniter User Guide Version 2.0.3

-
- - - - - - - - - -
- - -
- - - -
- - -

Tutorial − Static pages

- -

Note: This tutorial assumes you've downloaded CodeIgniter and installed the framework in your development environment.

- -

The first thing you're going to do is set up a controller to handle 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] -As URL schemes become more complex, this may change. But for now, this is all we will need to know.

- -

Create a file at application/controllers/pages.php with the following 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).

- -

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.

- -

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.

- - - -

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 includes the following code:

- - - -

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/ 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 order to load those pages, you'll have to check whether the requested page actually exists:

- -
-public function view($page = 'home')
-{
-			
-	if ( ! file_exists('application/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 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.

- -

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.

- -

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 the header and footer.

- -

Using custom routing rules, you have the power to map any URI to any 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.

- -
-$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 -(left-side) mapped to a controller and method name separated by slashes (right-side). -When a request comes in, CodeIgniter looks for the first match, and calls the appropriate controller and method, possibly with arguments.

- -

More information about routing can be found in the URI Routing documentation.

- -

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() method -in the pages controller? Awesome!

- -
- - - - - - - \ No newline at end of file diff --git a/user_guide_src/source/tutorial/static_pages.rst b/user_guide_src/source/tutorial/static_pages.rst new file mode 100644 index 000000000..3c95c8b25 --- /dev/null +++ b/user_guide_src/source/tutorial/static_pages.rst @@ -0,0 +1,148 @@ +Tutorial − Static pages +======================= + +**Note:** This tutorial assumes you've downloaded CodeIgniter and +`installed the framework <../installation/index.html>`_ in your +development environment. + +The first thing you're going to do is set up a **controller** to handle +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]`` +As URL schemes become more complex, this may change. But for now, this +is all we will need to know. + +Create a file at application/controllers/pages.php with the following +code. + +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 +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. + +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. + +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 +the header and footer. + +Using custom routing rules, you have the power to map any URI to any +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. + +:: + + $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 +(left-side) mapped to a controller and method name separated by slashes +(right-side). When a request comes in, CodeIgniter looks for the first +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>`_. + +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() +method in the pages controller? Awesome! -- cgit v1.2.3-24-g4f1b From 01b56bcb4e1188c37c5e9474d1427252b953f37f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 10 Oct 2011 10:45:45 -0400 Subject: Fixed some formatting issues with the changelog --- user_guide_src/source/changelog.rst | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 925785d13..d071f1c0d 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -30,22 +30,23 @@ Release Date: Not Released - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65) - url_title() will now trim extra dashes from beginning and end. - - Improved speed of String Helper's random_string() method - - Added XHTML Basic 1.1 doctype to HTML Helper. + - Improved speed of :doc:`String + Helper `'s random_string() method + - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. - Database - - Added a `CUBRID `_ driver to the `Database + - Added a `CUBRID `_ driver to the :doc:`Database Driver `. Thanks to the CUBRID team for supplying this patch. - - Added a PDO driver to the Database Driver. + - Added a PDO driver to the :doc:`Database Driver `. - Typecast limit and offset in the :doc:`Database Driver ` to integers to avoid possible injection. - Added additional option 'none' for the optional third argument for $this->db->like() in the :doc:`Database Driver `. - - Added $this->db->insert_batch() support to the OCI8 (Oracle) driver. + - Added $this->db->insert_batch() support to the OCI8 (Oracle) driver. - Libraries @@ -61,7 +62,7 @@ Release Date: Not Released - Added is_unique to the :doc:`Form Validation library `. - Modified valid_ip() to use PHP's filter_var() when possible (>= PHP 5.2) in the Form Validation library. - - Added $config['use_page_numbers'] to the Pagination library, which enables real page numbers in the URI. + - Added $config['use_page_numbers'] to the :doc:`Pagination library `, which enables real page numbers in the URI. - Added TLS and SSL Encryption for SMTP. - Core @@ -145,7 +146,7 @@ Release Date: August 20, 2011 Thanks to epallerols for the patch. - Added "application/x-csv" to mimes.php. - Added CSRF protection URI whitelisting. - - Fixed a bug where `Email library ` + - Fixed a bug where :doc:`Email library ` attachments with a "." in the name would using invalid MIME-types. - Added support for pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr -- cgit v1.2.3-24-g4f1b From 74479279a506c45d6fcd16e3f08469eb46cd1bed Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 10 Oct 2011 10:51:55 -0400 Subject: Fixed an extraneous new line --- user_guide_src/source/changelog.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index d071f1c0d..a6a2683aa 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -30,8 +30,7 @@ Release Date: Not Released - Altered form helper - made action on form_open_multipart helper function call optional. Fixes (#65) - url_title() will now trim extra dashes from beginning and end. - - Improved speed of :doc:`String - Helper `'s random_string() method + - Improved speed of :doc:`String Helper `'s random_string() method - Added XHTML Basic 1.1 doctype to :doc:`HTML Helper `. - Database -- cgit v1.2.3-24-g4f1b From c2b48812b1e1c3457ddaffb2fbbfcccb45554694 Mon Sep 17 00:00:00 2001 From: Joël Cox Date: Mon, 10 Oct 2011 20:24:46 +0200 Subject: Fixed markup glitches from HTML to RST parser. --- user_guide_src/source/index.rst | 3 +- user_guide_src/source/tutorial/conclusion.rst | 5 +- .../source/tutorial/create_news_items.rst | 29 ++++++--- .../source/tutorial/hard_coded_pages.rst | 73 ---------------------- user_guide_src/source/tutorial/index.rst | 16 ++++- user_guide_src/source/tutorial/news_section.rst | 7 ++- user_guide_src/source/tutorial/static_pages.rst | 40 +++++++++--- 7 files changed, 74 insertions(+), 99 deletions(-) delete mode 100644 user_guide_src/source/tutorial/hard_coded_pages.rst (limited to 'user_guide_src/source') 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 ------------------- +:: + +

Create a news item

+ + + + + + +
+ + +
+ + - Title - Text - + 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. - + + CodeIgniter 2 Tutorial + + + +

CodeIgniter 2 Tutorial

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: -**© 2011** +:: + + © 2011 + + Adding logic to the controller ------------------------------ @@ -72,6 +93,7 @@ page actually exists: :: + Date: Mon, 10 Oct 2011 16:26:27 -0500 Subject: incremental improvement to user guide ToC --- user_guide_src/source/_themes/eldocs/layout.html | 11 +++++++- .../_themes/eldocs/static/asset/css/common.css | 2 ++ user_guide_src/source/database/index.rst | 32 ++++++++++------------ user_guide_src/source/general/index.rst | 32 ++++++++++++++++++++-- user_guide_src/source/general/styleguide.rst | 7 +++-- user_guide_src/source/index.rst | 7 +++-- user_guide_src/source/overview/index.rst | 16 +++++------ 7 files changed, 71 insertions(+), 36 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/_themes/eldocs/layout.html b/user_guide_src/source/_themes/eldocs/layout.html index 4e083a1d3..ce54fa7ae 100644 --- a/user_guide_src/source/_themes/eldocs/layout.html +++ b/user_guide_src/source/_themes/eldocs/layout.html @@ -124,7 +124,16 @@ {%- block footer %} {%- endblock %} diff --git a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css index c216c3666..28182a162 100644 --- a/user_guide_src/source/_themes/eldocs/static/asset/css/common.css +++ b/user_guide_src/source/_themes/eldocs/static/asset/css/common.css @@ -119,6 +119,8 @@ img{ display: block; max-width: 100%; } fieldset{ border: 0; } .top{ float: right; } +.next{ padding: 0 20px 0 10px; } +.prev{ padding-right: 10px; } .highlight-ci, .highlight-ee, diff --git a/user_guide_src/source/database/index.rst b/user_guide_src/source/database/index.rst index 3b59986be..ab12b7cb7 100644 --- a/user_guide_src/source/database/index.rst +++ b/user_guide_src/source/database/index.rst @@ -6,24 +6,20 @@ CodeIgniter comes with a full-featured and very fast abstracted database class that supports both traditional structures and Active Record patterns. The database functions offer clear, simple syntax. -- :doc:`Quick Start: Usage Examples ` -- :doc:`Database Configuration ` -- :doc:`Connecting to a Database ` -- :doc:`Running Queries ` -- :doc:`Generating Query Results ` -- :doc:`Query Helper Functions ` -- :doc:`Active Record Class ` -- :doc:`Transactions ` -- :doc:`Table MetaData ` -- :doc:`Field MetaData ` -- :doc:`Custom Function Calls ` -- :doc:`Query Caching ` -- :doc:`Database manipulation with Database Forge ` -- :doc:`Database Utilities Class ` - .. toctree:: - :glob: :titlesonly: - :hidden: - * \ No newline at end of file + Quick Start: Usage Examples + Database Configuration + Connecting to a Database + Running Queries + Generating Query Results + Query Helper Functions + Active Record Class + Transactions + Table MetaData + Field MetaData + Custom Function Calls + Query Caching + Database Manipulation with Database Forge + Database Utilities Class \ No newline at end of file diff --git a/user_guide_src/source/general/index.rst b/user_guide_src/source/general/index.rst index 1ece12bef..2bc684a1d 100644 --- a/user_guide_src/source/general/index.rst +++ b/user_guide_src/source/general/index.rst @@ -1,6 +1,32 @@ +############## +General Topics +############## + .. toctree:: - :glob: - :hidden: :titlesonly: - * \ No newline at end of file + urls + controllers + reserved_names + views + models + Helpers + libraries + creating_libraries + drivers + creating_drivers + core_classes + ancillary_classes + hooks + autoloader + common_functions + routing + errors + Caching + profiling + cli + managing_apps + environments + alternative_php + security + PHP Style Guide \ No newline at end of file diff --git a/user_guide_src/source/general/styleguide.rst b/user_guide_src/source/general/styleguide.rst index 0373fc791..b3dc08871 100644 --- a/user_guide_src/source/general/styleguide.rst +++ b/user_guide_src/source/general/styleguide.rst @@ -1,6 +1,7 @@ -######################## -General Style and Syntax -######################## +############### +PHP Style Guide +############### + The following page describes the use of coding rules adhered to when developing CodeIgniter. diff --git a/user_guide_src/source/index.rst b/user_guide_src/source/index.rst index e53182550..b95161271 100644 --- a/user_guide_src/source/index.rst +++ b/user_guide_src/source/index.rst @@ -37,9 +37,12 @@ CodeIgniter is right for you if: * overview/index + general/requirements installation/index general/index libraries/index - database/index helpers/index - documentation/index \ No newline at end of file + database/index + documentation/index + general/quick_reference + general/credits \ No newline at end of file diff --git a/user_guide_src/source/overview/index.rst b/user_guide_src/source/overview/index.rst index d541e796c..dc91f78c4 100644 --- a/user_guide_src/source/overview/index.rst +++ b/user_guide_src/source/overview/index.rst @@ -4,15 +4,13 @@ CodeIgniter Overview The following pages describe the broad concepts behind CodeIgniter: -- :doc:`CodeIgniter at a Glance ` -- :doc:`Supported Features ` -- :doc:`Application Flow Chart ` -- :doc:`Introduction to the Model-View-Controller ` -- :doc:`Design and Architectural Goals ` - .. toctree:: - :glob: - :hidden: :titlesonly: - * \ No newline at end of file + Getting Started + CodeIgniter at a Glance + CodeIgniter Cheatsheets + Supported Features + Application Flow Chart + Model-View-Controller + Architectural Goals \ No newline at end of file -- cgit v1.2.3-24-g4f1b From 9286a8f71305f557997401b55138e8ef483839f9 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 10 Oct 2011 16:46:43 -0500 Subject: unhid general topics ToC for navigation --- user_guide_src/source/general/index.rst | 1 - 1 file changed, 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/general/index.rst b/user_guide_src/source/general/index.rst index 1335e9dd4..2162b8140 100644 --- a/user_guide_src/source/general/index.rst +++ b/user_guide_src/source/general/index.rst @@ -4,7 +4,6 @@ General Topics .. toctree:: :titlesonly: - :hidden: urls controllers -- cgit v1.2.3-24-g4f1b From 8352f093567caf7e64e38698b6d9cf65396d5a10 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 10 Oct 2011 17:22:33 -0500 Subject: removed 'index' listing from tutorial index toc --- user_guide_src/source/tutorial/index.rst | 1 - 1 file changed, 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/tutorial/index.rst b/user_guide_src/source/tutorial/index.rst index eb6f11e34..c959d04d2 100644 --- a/user_guide_src/source/tutorial/index.rst +++ b/user_guide_src/source/tutorial/index.rst @@ -40,7 +40,6 @@ Enjoy your exploration of the CodeIgniter framework. :hidden: :titlesonly: - index static_pages news_section create_news_items -- cgit v1.2.3-24-g4f1b From bb859fd844ce085ffc78eb8ad250d1a436a84e18 Mon Sep 17 00:00:00 2001 From: Fumito Mizuno Date: Fri, 14 Oct 2011 20:05:34 +0900 Subject: Line Break for L165 $mysql = '20061124092345'; $unix = mysql_to_unix($mysql); --- user_guide_src/source/helpers/date_helper.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/helpers/date_helper.rst b/user_guide_src/source/helpers/date_helper.rst index 378ff362b..ad06dd628 100644 --- a/user_guide_src/source/helpers/date_helper.rst +++ b/user_guide_src/source/helpers/date_helper.rst @@ -162,7 +162,8 @@ Example :: - $mysql = '20061124092345'; $unix = mysql_to_unix($mysql); + $mysql = '20061124092345'; + $unix = mysql_to_unix($mysql); unix_to_human() =============== -- cgit v1.2.3-24-g4f1b From 48d8fb6e9b58776abc96761dbd18e543418df4d7 Mon Sep 17 00:00:00 2001 From: Kyle Farris Date: Fri, 14 Oct 2011 17:59:49 -0300 Subject: Updated to new documentation for new active record methods. --- user_guide_src/source/database/active_record.rst | 108 +++++++++++++++++++++++ 1 file changed, 108 insertions(+) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst index e1fc00bc5..7230812de 100644 --- a/user_guide_src/source/database/active_record.rst +++ b/user_guide_src/source/database/active_record.rst @@ -54,6 +54,36 @@ $query, which can be used to show the results:: Please visit the :doc:`result functions ` page for a full discussion regarding result generation. +$this->db->get_compiled_select() +================================ + +Compiles the selection query just like `$this->db->get()`_ but does not *run* +the query. This method simply returns the SQL query as a string. + +Example:: + + $sql = $this->db->get_compiled_select('mytable'); + echo $sql; + + // Produces string: SELECT * FROM mytable + +The second parameter enables you to set whether or not the active record query +will be reset (by default it will be—just like `$this->db->get()`):: + + echo $this->db->limit(10,20)->get_compiled_select('mytable', FALSE); + // Produces string: SELECT * FROM mytable LIMIT 20, 10 + // (in MySQL. Other databases have slightly different syntax) + + echo $this->db->select('title, content, date')->get_compiled_select(); + + // Produces string: SELECT title, content, date FROM mytable + +The key thing to notice in the above example is that the second query did not +utlize `$this->db->from()`_ and did not pass a table name into the first +parameter. The reason for this outcome is because the query has not been +executed using `$this->db->get()`_ which resets values or reset directly +using `$this-db->reset_query()`_. + $this->db->get_where() ====================== @@ -540,6 +570,41 @@ object. .. note:: All values are escaped automatically producing safer queries. +$this->db->get_compiled_insert() +================================ +Compiles the insertion query just like `$this->db->insert()`_ but does not +*run* the query. This method simply returns the SQL query as a string. + +Example:: + + $data = array( + 'title' => 'My title', + 'name' => 'My Name', + 'date' => 'My date' + ); + + $sql = $this->db->set($data)->get_compiled_insert('mytable'); + echo $sql; + + // Produces string: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date') + +The second parameter enables you to set whether or not the active record query +will be reset (by default it will be--just like `$this->db->insert()`_):: + + echo $this->db->set('title', 'My Title')->get_compiled_insert('mytable', FALSE); + + // Produces string: INSERT INTO mytable (title) VALUES ('My Title') + + echo $this->db->set('content', 'My Content')->get_compiled_insert(); + + // Produces string: INSERT INTO mytable (title, content) VALUES ('My Title', 'My Content') + +The key thing to notice in the above example is that the second query did not +utlize `$this->db->from()`_ nor did it pass a table name into the first +parameter. The reason this worked is because the query has not been executed +using `$this->db->insert()`_ which resets values or reset directly using +`$this->db->reset_query()`_. + $this->db->insert_batch() ========================= @@ -717,6 +782,14 @@ array of values, the third parameter is the where key. .. note:: All values are escaped automatically producing safer queries. +$this->db->get_compiled_update() +================================ + +This works exactly the same way as ``$this->db->get_compiled_insert()`` except +that it produces an UPDATE SQL string instead of an INSERT SQL string. + +For more information view documentation for `$this->get_compiled_insert()`_. + ************* Deleting Data @@ -784,6 +857,13 @@ Generates a truncate SQL string and runs the query. .. note:: If the TRUNCATE command isn't available, truncate() will execute as "DELETE FROM table". + +$this->db->get_compiled_delete() +================================ +This works exactly the same way as ``$this->db->get_compiled_insert()`` except +that it produces a DELETE SQL string instead of an INSERT SQL string. + +For more information view documentation for `$this->get_compiled_insert()`_. *************** Method Chaining @@ -854,3 +934,31 @@ Here's a usage example:: where, like, group_by, having, order_by, set + +******************* +Reset Active Record +******************* + +Resetting Active Record allows you to start fresh with your query without +executing it first using a method like $this->db->get() or $this->db->insert(). +Just like the methods that execute a query, this will *not* reset items you've +cached using `Active Record Caching`_. + +This is useful in situations where you are using Active Record to generate SQL +(ex. ``$this->db->get_compiled_select()``) but then choose to, for instance, +run the query:: + + // Note that the second parameter of the get_compiled_select method is FALSE + $sql = $this->db->select(array('field1','field2')) + ->where('field3',5) + ->get_compiled_select('mytable', FALSE); + + // ... + // Do something crazy with the SQL code... like add it to a cron script for + // later execution or something... + // ... + + $data = $this->db->get()->result_array(); + + // Would execute and return an array of results of the following query: + // SELECT field1, field1 from mytable where field3 = 5; -- cgit v1.2.3-24-g4f1b From 053dbc851f4c209ae05e1f079bb6da22e629b507 Mon Sep 17 00:00:00 2001 From: Kyle Farris Date: Fri, 14 Oct 2011 18:06:52 -0300 Subject: Updated changelog to new changelog format. --- user_guide_src/source/changelog.rst | 3 +++ 1 file changed, 3 insertions(+) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index a6a2683aa..d0b935224 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -46,6 +46,9 @@ Release Date: Not Released $this->db->like() in the :doc:`Database Driver `. - Added $this->db->insert_batch() support to the OCI8 (Oracle) driver. + - Added new :doc:`Active Record ` methods that return + the SQL string of queries without executing them: get_compiled_select(), + get_compiled_insert(), get_compiled_update(), get_compiled_delete(). - Libraries -- cgit v1.2.3-24-g4f1b From 4d7c27eec7995c94f60ba421e209eb5a2da08711 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 15 Oct 2011 12:02:32 +0800 Subject: Fix #576: using ini_get() to detect if apc is enabled or not --- user_guide_src/source/changelog.rst | 1 + 1 file changed, 1 insertion(+) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 925785d13..a5044e07b 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -108,6 +108,7 @@ Bug fixes for 2.1.0 - Fixed a bug (#484) - First time _csrf_set_hash() is called, hash is never set to the cookie (in Security.php). - Fixed a bug (#60) - Added _file_mime_type() method to the `File Uploading Library ` in order to fix a possible MIME-type injection. - Fixed a bug (#537) - Support for all wav type in browser. +- Fixed a bug (#576) - Using ini_get() function to detect if apc is enabled or not. Version 2.0.3 ============= -- cgit v1.2.3-24-g4f1b From 2d096c0339f1cef810cc74e93f4d0633ee8e215f Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 17 Oct 2011 12:24:56 -0400 Subject: Added changelog item --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 3e1643524..0b12d758c 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -8,7 +8,7 @@ Version 2.1.0 (planned) Release Date: Not Released - General Changes - + - Added an optional backtrace to php-error template - Added Android to the list of user agents. - Added Windows 7 to the list of user platforms. - Callback validation rules can now accept parameters like any other -- cgit v1.2.3-24-g4f1b From deb65968c2be11b72f1072d5fd840edd1da031dd Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 17 Oct 2011 12:26:02 -0400 Subject: Added changelog item --- user_guide_src/source/changelog.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 0b12d758c..e4c318f43 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -8,7 +8,8 @@ Version 2.1.0 (planned) Release Date: Not Released - General Changes - - Added an optional backtrace to php-error template + + - Added an optional backtrace to php-error template, - Added Android to the list of user agents. - Added Windows 7 to the list of user platforms. - Callback validation rules can now accept parameters like any other -- cgit v1.2.3-24-g4f1b From 52aff71bac8bf93eff797e35d875334ebd3585a0 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 17 Oct 2011 12:26:56 -0400 Subject: Added changelog item --- user_guide_src/source/changelog.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index e4c318f43..97e949542 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -9,7 +9,7 @@ Release Date: Not Released - General Changes - - Added an optional backtrace to php-error template, + - Added an optional backtrace to php-error template. - Added Android to the list of user agents. - Added Windows 7 to the list of user platforms. - Callback validation rules can now accept parameters like any other -- cgit v1.2.3-24-g4f1b From caa1db64141cc8bfbdbe3a4f6f7b639331d5d3ba Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 17 Oct 2011 21:17:21 -0500 Subject: added some additional notes to the 2.0.0 update notes to highlight some of the potential gotchas, fixes #588 --- user_guide_src/source/changelog.rst | 2 + user_guide_src/source/installation/upgrade_200.rst | 52 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index 906e2ebaa..bbf2ec778 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -323,6 +323,8 @@ Bug fixes for 2.0.1 - Fixed a bug (Reactor #69) where the SHA1 library was named incorrectly. +.. _2.0.0-changelog: + Version 2.0.0 ============= diff --git a/user_guide_src/source/installation/upgrade_200.rst b/user_guide_src/source/installation/upgrade_200.rst index 064e1b534..0bcbd5c99 100644 --- a/user_guide_src/source/installation/upgrade_200.rst +++ b/user_guide_src/source/installation/upgrade_200.rst @@ -5,6 +5,10 @@ Upgrading from 1.7.2 to 2.0.0 Before performing an update you should take your site offline by replacing the index.php file with a static one. +******************* +Update Instructions +******************* + Step 1: Update your CodeIgniter files ===================================== @@ -88,3 +92,51 @@ Step 8: Update your user guide Please replace your local copy of the user guide with the new version, including the image files. + + +************ +Update Notes +************ + +Please refer to the :ref:`2.0.0 Change Log <2.0.0-changelog>` for full +details, but here are some of the larger changes that are more likely to +impact your code: + +- CodeIgniter now requires PHP 5.1.6. +- Scaffolding has been removed. +- The CAPTCHA plugin in now a :doc:`helper `. +- The JavaScript calendar plugin was removed. +- The *system/cache* and *system/logs* directories are now in the application + directory. +- The Validation class has been removed. Please see the + :doc:`Form Validation library ` +- "default" is now a reserved name. +- The xss_clean() function has moved to the :doc:`Security Class + `. +- do_xss_clean() now returns FALSE if the uploaded file fails XSS checks. +- The :doc:`Session Class ` requires now the use of an + encryption key set in the config file. +- The following deprecated Active Record functions have been removed: + ``orwhere``, ``orlike``, ``groupby``, ``orhaving``, ``orderby``, + ``getwhere``. +- ``_drop_database()`` and ``_create_database()`` functions have been removed + from the db utility drivers. +- The ``dohash()`` function of the :doc:`Security helper + ` + has been renamed to ``do_hash()`` for naming consistency. + +The config folder +================= + +The following files have been changed: + +- config.php +- database.php +- mimes.php +- routes.php +- user_agents.php + +The following files have been added: + +- foreign_chars.php +- profiler.php -- cgit v1.2.3-24-g4f1b From 84bcc6e9b8b1648d3a52102d2a96d617c60508f0 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 17 Oct 2011 21:24:27 -0500 Subject: fixed typo in AR docs. NOTE: Sphinx gives a ReST error for unknown title targets, but they do exist, and links are built properly --- user_guide_src/source/database/active_record.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/database/active_record.rst b/user_guide_src/source/database/active_record.rst index 7230812de..5555a30bc 100644 --- a/user_guide_src/source/database/active_record.rst +++ b/user_guide_src/source/database/active_record.rst @@ -79,11 +79,12 @@ will be reset (by default it will be—just like `$this->db->get()`):: // Produces string: SELECT title, content, date FROM mytable The key thing to notice in the above example is that the second query did not -utlize `$this->db->from()`_ and did not pass a table name into the first +utilize `$this->db->from()`_ and did not pass a table name into the first parameter. The reason for this outcome is because the query has not been executed using `$this->db->get()`_ which resets values or reset directly using `$this-db->reset_query()`_. + $this->db->get_where() ====================== -- cgit v1.2.3-24-g4f1b From 961684280faccb7f32da700201422ecd8a454a0a Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Mon, 17 Oct 2011 22:57:44 -0500 Subject: updated Directory helper docs to use proper PHP method Sphinx roles --- user_guide_src/source/helpers/directory_helper.rst | 27 +++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/helpers/directory_helper.rst b/user_guide_src/source/helpers/directory_helper.rst index 6c259adb1..fd169886c 100644 --- a/user_guide_src/source/helpers/directory_helper.rst +++ b/user_guide_src/source/helpers/directory_helper.rst @@ -18,15 +18,20 @@ This helper is loaded using the following code The following functions are available: -directory_map('source directory') -================================= +directory_map() +=============== This function reads the directory path specified in the first parameter and builds an array representation of it and all its contained files. + +.. php:method:: directory_map($source_dir[, $directory_depth = 0[, $hidden = FALSE]]) -Example - -:: + :param string $source_dir: path to the ource directory + :param integer $directory_depth: depth of directories to traverse (0 = + fully recursive, 1 = current dir, etc) + :param boolean $hidden: whether to include hidden directories + +Examples:: $map = directory_map('./mydirectory/'); @@ -35,23 +40,17 @@ Example Sub-folders contained within the directory will be mapped as well. If you wish to control the recursion depth, you can do so using the second -parameter (integer). A depth of 1 will only map the top level directory - -:: +parameter (integer). A depth of 1 will only map the top level directory:: $map = directory_map('./mydirectory/', 1); By default, hidden files will not be included in the returned array. To -override this behavior, you may set a third parameter to true (boolean) - -:: +override this behavior, you may set a third parameter to true (boolean):: $map = directory_map('./mydirectory/', FALSE, TRUE); Each folder name will be an array index, while its contained files will -be numerically indexed. Here is an example of a typical array - -:: +be numerically indexed. Here is an example of a typical array:: Array (     [libraries] => Array     -- cgit v1.2.3-24-g4f1b From 68647366bce35e180e086902bd6ec9557422ac94 Mon Sep 17 00:00:00 2001 From: kenjis Date: Tue, 18 Oct 2011 23:33:23 +0900 Subject: fix changelog difference between HTML and RST --- user_guide_src/source/changelog.rst | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'user_guide_src/source') diff --git a/user_guide_src/source/changelog.rst b/user_guide_src/source/changelog.rst index bbf2ec778..8598585ce 100644 --- a/user_guide_src/source/changelog.rst +++ b/user_guide_src/source/changelog.rst @@ -58,6 +58,8 @@ Release Date: Not Released - Added support to set an optional parameter in your callback rules of validation using the :doc:`Form Validation Library `. + - Added a :doc:`Migration Library ` to assist with applying + incremental updates to your database schema. - Driver children can be located in any package path. - Added max_filename_increment config setting for Upload library. - CI_Loader::_ci_autoloader() is now a protected method. @@ -151,14 +153,6 @@ Release Date: August 20, 2011 - Added CSRF protection URI whitelisting. - Fixed a bug where :doc:`Email library ` attachments with a "." in the name would using invalid MIME-types. - - Added support for - pem,p10,p12,p7a,p7c,p7m,p7r,p7s,crt,crl,der,kdb,rsa,cer,sst,csr - Certs to mimes.php. - - Added support pgp,gpg to mimes.php. - - Added support 3gp, 3g2, mp4, wmv, f4v, vlc Video files to - mimes.php. - - Added support m4a, aac, m4u, xspf, au, ac3, flac, ogg Audio files - to mimes.php. - Helpers -- cgit v1.2.3-24-g4f1b