From befdc87b1ce6caf47c6f8b1dfa02333dfee8a950 Mon Sep 17 00:00:00 2001 From: Derek Allard Date: Tue, 9 Oct 2007 13:25:27 +0000 Subject: Added the ability to auto-load Models --- user_guide/general/autoloader.html | 1 + user_guide/general/models.html | 19 ++++++++++--------- 2 files changed, 11 insertions(+), 9 deletions(-) (limited to 'user_guide/general') diff --git a/user_guide/general/autoloader.html b/user_guide/general/autoloader.html index 55b3c0d38..c90120cc8 100644 --- a/user_guide/general/autoloader.html +++ b/user_guide/general/autoloader.html @@ -74,6 +74,7 @@ consider auto-loading them for convenience.

  • Plugins found in the "plugins" folder
  • Custom config files found in the "config" folder
  • Language files found in the "system/language" folder
  • +
  • Models found in the "models" folder
  • To autoload resources, open the application/config/autoload.php file and add the item you want diff --git a/user_guide/general/models.html b/user_guide/general/models.html index f2a676188..b111eacca 100644 --- a/user_guide/general/models.html +++ b/user_guide/general/models.html @@ -70,13 +70,13 @@ Models

  • What is a Model?
  • Anatomy of a Model
  • Loading a Model
  • +
  • Auto-Loading a Model
  • Connecting to your Database
  • - - -

    What is a Model?

    + +

    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 @@ -124,8 +124,8 @@ class Blogmodel extends Model {

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

    - -

    Anatomy of a Model

    + +

    Anatomy of a Model

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

    @@ -161,8 +161,8 @@ class User_model extends Model {
    application/models/user_model.php - -

    Loading a Model

    + +

    Loading a Model

    Your models will typically be loaded and called from within your controller functions. To load a model you will use the following function:

    @@ -207,10 +207,11 @@ class Blog_controller extends 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 mdoel to the autoload array.

    - -

    Connecting to your Database

    +

    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:

    -- cgit v1.2.3-24-g4f1b