Welcome Guest, Not a member yet? Register   Sign In
Creating a new "shared" folder for models and libraries
#7

[eluser]Unknown[/eluser]
Dear folks, i am new in this forum. First of all, sorry for my poor english :-)

The sharing of models it's really a common task. In my case, i must use a authentication component like redux_auth for more than one application/module. But this - or other compontents - consist of at least one library, model(s) and configuration files.

The sharing of the libraries is simple: storing into the CI-libraries folder. The sharing of configs are also a simple task (eg. load by 'require_once' into the controller), because commonly they are no dependencies to other classes/modules.

Maybe, there is a short solution with some minor changes at the core code of CI:
* Edit the 'Loader.php' of your CI-Installation (CI 1.7.1, 1.7.2);
* Pickup the 'model'-Method (near to line 115);
* Go to the line (near Line 160):
Code:
.
        $model = strtolower($model);

and add this lines:
Code:
.
        $model       = strtolower($model);
        $LoadState   = FALSE;
        $LoadPath    = FALSE;

* Than replace the following statements:
Code:
.
        if ( ! file_exists(APPPATH.'models/'.$path.$model.EXT))
        {
            show_error('Unable to locate the model you have specified: '.$model);
        }

by
Code:
.
        if( $LoadState === FALSE AND file_exists(APPPATH.'models/'.$path.$model.EXT))
        {
            $LoadState    = TRUE;
            $LoadPath    = APPPATH;
        }
        
        if( $LoadState === FALSE AND file_exists(BASEPATH.'models/'.$path.$model.EXT))
        {
            $LoadState    = TRUE;
            $LoadPath    = BASEPATH;
        }

        if ( $LoadState === false )
        {
            show_error('Unable to locate the model you have specified: '.$model);
        }

* Each 'if'-Statement represents one directory lookup. The first match wins and set the LoadPath-Variable.
* Finally, you must modify the 'require_once'-Statement near line 180 from:
Code:
.
        require_once(APPPATH.'models/'.$path.$model.EXT);

to

Code:
.
        require_once($LoadPath.'models/'.$path.$model.EXT);

This approach works very well for me.

With best regards

[edit] Uuuups, sorry - i take a look at your MY_Loader-Class.
It's basically the same solution :-)


Messages In This Thread
Creating a new "shared" folder for models and libraries - by El Forum - 11-27-2009, 02:45 AM
Creating a new "shared" folder for models and libraries - by El Forum - 11-27-2009, 03:32 AM
Creating a new "shared" folder for models and libraries - by El Forum - 12-20-2009, 02:49 AM
Creating a new "shared" folder for models and libraries - by El Forum - 12-21-2009, 08:36 AM
Creating a new "shared" folder for models and libraries - by El Forum - 12-21-2009, 01:21 PM
Creating a new "shared" folder for models and libraries - by El Forum - 12-24-2009, 04:46 AM
Creating a new "shared" folder for models and libraries - by El Forum - 01-01-2010, 02:26 PM
Creating a new "shared" folder for models and libraries - by El Forum - 01-03-2010, 09:02 AM
Creating a new "shared" folder for models and libraries - by El Forum - 02-18-2010, 10:00 AM
Creating a new "shared" folder for models and libraries - by El Forum - 09-24-2010, 06:53 AM
Creating a new "shared" folder for models and libraries - by El Forum - 07-30-2014, 01:29 PM
Creating a new "shared" folder for models and libraries - by El Forum - 08-04-2014, 08:50 AM
Creating a new "shared" folder for models and libraries - by El Forum - 08-04-2014, 09:35 AM
Creating a new "shared" folder for models and libraries - by El Forum - 08-27-2014, 10:25 AM
Creating a new "shared" folder for models and libraries - by El Forum - 08-29-2014, 09:09 PM



Theme © iAndrew 2016 - Forum software by © MyBB