From 33de9a144aad28763405f8ae2d5c59df5e929b4f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 28 Sep 2006 06:50:16 +0000 Subject: --- user_guide/general/controllers.html | 1 + user_guide/general/creating_libraries.html | 70 ++++++++---------------------- 2 files changed, 19 insertions(+), 52 deletions(-) (limited to 'user_guide') diff --git a/user_guide/general/controllers.html b/user_guide/general/controllers.html index a197299d5..0bfe973e5 100644 --- a/user_guide/general/controllers.html +++ b/user_guide/general/controllers.html @@ -381,6 +381,7 @@ is a list of reserved names. Do not name your controller functions any of these
  • _ci_init_scaffolding
  • _ci_is_loaded
  • _ci_load
  • +
  • _ci_load_class
  • _ci_scaffolding
  • _ci_set_view_path
  • diff --git a/user_guide/general/creating_libraries.html b/user_guide/general/creating_libraries.html index b047838be..a2d40f95d 100644 --- a/user_guide/general/creating_libraries.html +++ b/user_guide/general/creating_libraries.html @@ -63,14 +63,27 @@ Creating Libraries

    Creating Libraries

    When we use the term "Libraries" we are normally referring to the classes that are located in the libraries -directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create your own libraries within -your application directory in order to maintain separation between your local resources and the global framework resources.

    +directory and described in the Class Reference of this user guide. In this case, however, we will instead describe how you can create +your own libraries within your application/libraries directory in order to maintain separation between your local resources +and the global framework resources.

    + +

    As an added bonus, Code Igniter permits your libraries to extend native classes if you simply need to add some functionality +to an existing library. Or you can even replace native libraries just by placing identically named versions in your application/libraries folder. + +

    In summary:

    + + + +

    Storage

    Your library classes should be placed within your application/libraries folder, as this is where Code Igniter will look for them when -they are initialized. If your class is named identically to a native class from the system/libraries folder, your version -will be used instead.

    +they are initialized.

    Naming Conventions

    @@ -87,10 +100,6 @@ will be used instead.

    Classes should have this basic prototype (Note: We are using the name Myclass purely as an example):

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    -
    -// Initialize the class
    -$obj =& get_instance();
    -$obj->init_class('Myclass');

    class Myclass {

    @@ -101,15 +110,6 @@ class Myclass {
    ?>
    -

    You'll notice in the above example that the class is instantiated directly from the file itself using these two lines of code:

    - -$obj =& get_instance();
    -$obj->init_class('Myclass');
    - -

    Make sure and submit your class name in the first parameter of the $obj->init_class() function. In the -above example it is Myclass

    - -

    Using Your Class

    From within any of your Controller functions you can initialize your class using the standard:

    @@ -124,22 +124,6 @@ Code Igniter doesn't care.

    $this->myclass->some_function();  // Object instances will always be lower case -

    Setting a Different Class Variable Name

    - - -

    If you would like the object variable ($this->myclass) set to a different name you can specify it when initializing your class. For -example, let's initialize it as foobar:

    - -$obj =& get_instance();
    -$obj->init_class('Myclass', 'foobar');
    - -

    In the above example you would still load your class like this:

    - -$this->load->library('Mclass'); - -

    But you would use it like this:

    - -$this->foobar->function();

    Passing Parameters When Initializing Your Class

    @@ -169,25 +153,7 @@ class Myclass {
    }

    ?> -

    You can also pass parameters via the third parameter of the $obj->init_class() function:

    - -<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    -
    - -$params = array('type' => 'large', 'color' => 'red');

    - -// Initialize the class
    -$obj =& get_instance();
    -$obj->init_class('Myclass', 'myclass', $params); -

    -class Myclass {
    -
    -    function Myclass($params)
    -    {
    -        // Do something with $params
    -    }
    -}

    -?>
    +

    You can also pass parameters stored in a config file. Simply create a config file named identically to the class filename.

    -- cgit v1.2.3-24-g4f1b