Welcome Guest, Not a member yet? Register   Sign In
[HOW] CI Works
#11

[eluser]4ever[/eluser]
OK. I found that

1) static used in functions makes the variable saving the value for the next call.

2) ...

I hope i say it right.

However

1) how does CodeIgniter access the static variables $_is_loaded and $_classes? I've seen them setting

I've seen only function load_class using call
Code:
is_loaded($class);
to save variable value

Can you use some other way to access the static variable in function? We don't see it in scope of Super object...
#12

[eluser]4ever[/eluser]
OK, I go to write how I understand CI_loader.

L78 function library
L80 if 1st argument is array make recursive call
L90 exit if 1st argument of class name is not present OR if the controller class is already loaded
L100 load the requested class
Code:
$this->_ci_load_class($library, $params, $object_name);





L116 function model
L122 if 1st argument is array make recursive call
L127 exit if 1st argument of model name is not present
L135 checks format of model name and gets two parts: $path, $model
L144 if ($name == '') $name = $model;
L149 if the model is loaded return
Code:
in_array($name, $this->_ci_models, TRUE)
L154 access the super object:
Code:
$CI =& get_instance();
L161 $model = strtolower($model);
L162-192
Code:
foreach ($this->_ci_model_paths as $mod_path)
        {
            if ( ! file_exists($mod_path.'models/'.$path.$model.EXT))
            {
                continue;
            }

            if ($db_conn !== FALSE AND ! class_exists('CI_DB'))
            {
                if ($db_conn === TRUE)
                {
                    $db_conn = '';
                }

                $CI->load->database($db_conn, FALSE, TRUE);
            }

            if ( ! class_exists('CI_Model'))
            {
                load_class('Model', 'core');
            }

            require_once($mod_path.'models/'.$path.$model.EXT);

            $model = ucfirst($model);

            $CI->$name = new $model();

            $this->_ci_models[] = $name;
            return;
        }

L165 find the file of model
L169-L176 if 3rd fnc argument - DB connection is set ...
make db connection
Code:
$CI->load->database($db_conn, FALSE, TRUE);
L179-181 if class has been defined load the CORE MODEL
Code:
load_class('Model', 'core');
This has been explain in previous posts of this thread.
L184 REQUIRE the user model
L188-190 It is possible to save the $name as 2nd function argument and to save the object under different name.
Code:
$CI->$name = new $model();
$this->_ci_models[] = $name;
So here the instance has been created and object is saved in super object -> _ci_models array
#13

[eluser]4ever[/eluser]
OK now the function database

Code:
function database($params = '', $return = FALSE, $active_record = NULL)
    {
        // Grab the super object
        $CI =& get_instance();

        // Do we even need to load the database class?
        if (class_exists('CI_DB') AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db))
        {
            return FALSE;
        }

        require_once(BASEPATH.'database/DB'.EXT);

        if ($return === TRUE)
        {
            return DB($params, $active_record);
        }

        // Initialize the db variable.  Needed to prevent
        // reference errors with some configurations
        $CI->db = '';

        // Load the DB class
        $CI->db =& DB($params, $active_record);
    }

Now I have two questions:

1) why or what is it good for to return object with this method?
2) why the load of DB class is made by the reference ("L232)?

I will need to check system/database/DB.php

PS: I have made a stylistic change to the post #2 and there is two new question to the load_class... (maybe they are not new, I am not sure, but I think I have no answer for them)




Theme © iAndrew 2016 - Forum software by © MyBB