From 37f4b9caa02783e06dd7c5318200113409a0deb1 Mon Sep 17 00:00:00 2001 From: Derek Jones Date: Fri, 1 Jul 2011 17:56:50 -0500 Subject: backed out 648b42a75739, which was a NON-trivial whitespace commit. It broke the Typography class's string replacements, for instance --- user_guide/general/models.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'user_guide/general/models.html') diff --git a/user_guide/general/models.html b/user_guide/general/models.html index c0e494351..117c810b7 100644 --- a/user_guide/general/models.html +++ b/user_guide/general/models.html @@ -72,8 +72,8 @@ Models

What is a Model?

-

Models are PHP classes that are designed to work with information in your database. For example, let's say -you use CodeIgniter to manage a blog. You might have a model class that contains functions to insert, update, and +

Models are PHP classes that are designed to work with information in your database. For example, let's say +you use CodeIgniter to manage a blog. You might have a model class that contains functions to insert, update, and retrieve your blog data. Here is an example of what such a model class might look like:

@@ -116,10 +116,10 @@ class Blogmodel extends CI_Model {
}

Note: The functions in the above example use the Active Record database functions.

-

Note: For the sake of simplicity in this example we're using $_POST directly. This is generally bad practice, and a more common approach would be to use the Input Class $this->input->post('title')

+

Note: For the sake of simplicity in this example we're using $_POST directly. This is generally bad practice, and a more common approach would be to use the Input Class $this->input->post('title')

Anatomy of a Model

-

Model classes are stored in your application/models/ folder. They can be nested within sub-folders if you +

Model classes are stored in your application/models/ folder. They can be nested within sub-folders if you want this type of organization.

The basic prototype for a model class is this:

@@ -134,10 +134,10 @@ class Model_name extends CI_Model {
    }
} -

Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. +

Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

-

The file name will be a lower case version of your class name. For example, if your class is this:

+

The file name will be a lower case version of your class name. For example, if your class is this:

class User_model extends CI_Model {
@@ -161,7 +161,7 @@ To load a model you will use the following function:

$this->load->model('Model_name'); -

If your model is located in a sub-folder, include the relative path from your models folder. For example, if +

If your model is located in a sub-folder, include the relative path from your models folder. For example, if you have a model located at application/models/blog/queries.php you'll load it using:

$this->load->model('blog/queries'); @@ -200,12 +200,12 @@ class Blog_controller extends CI_Controller {
}

Auto-loading Models

-

If you find that you need a particular model globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the model to the autoload array.

+

If you find that you need a particular model globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization. This is done by opening the application/config/autoload.php file and adding the model to the autoload array.

Connecting to your Database

-

When a model is loaded it does NOT connect automatically to your database. The following options for connecting are available to you:

+

When a model is loaded it does NOT connect automatically to your database. The following options for connecting are available to you: