• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
COREPATH not used for core-classes

I definded an alternative corepath in index.php
// Path to the core folder
I've been using this for a while without problems. I have a MY_CI_model class in that location that extends the standard CI_model and that works fine.

Now I wanted to extend the URI class.

So I created a file called MY_URI.php with code:
class MY_URI extends CI_URI
    public function __construct()
        //just to check if this file is used
        echo "ok";die;
The code in the constructor is not run.

When I put this file in de core directory of my application it works.

Shouldnt CI look for that file in COREPATH/core ?

I just noticed something.

If I put an empty file called MY_URI.php in the application's core directory, the MY_URI class in the COREPATH directory is used.
So it seems that a file with that name has to exist in the application's core directory to make it work...

What version of CI are you using? Mine (2.1.2) doesn't even any constant called COREPATH neither in index.php nor any other file of a basic CI installation/download.

So I'm wondering what that COREPATH you got should actually be useful for...

Sorry, you're correct.

We used Phil Sturgeon’s autoload code

| -------------------------------------------------------------------
|  Native Auto-load
| -------------------------------------------------------------------
| Nothing to do with config/autoload.php, this allows PHP autoload to work
| for base controllers and some third-party libraries.
function __autoload($class)
    if (strpos($class, 'CI_') !== 0):
        @include_once( APPPATH . 'core/'. $class . EXT );

But we defined a constant COREPATH so we can put the core files in a central location on the server.

function __autoload($class)
if(strpos($class, 'CI_') !== 0)
@include_once( COREPATH . 'core/'. $class . EXT );

This does not seem to work for the core classes that are loaded automaticaly.

Is there a way to use a central location for the core,library and helper files?
I want to be able to use the same classes from all my applications, without having to copy them each time I start a new application. This makes updating these files difficult because they are scattered all over my site.

For the libraries en helpers I now use a symbolic link so that the folder points to the central location, but i've got a feeling that's not the correct way to do it.
Can't find anything about this on the codeigniter site. Strange, because it seems like a common problem.

Sure it is possible. And by the way you can achieve it even easier than you did there Wink

Update your index.php and change $system_path to an absolute path to where your files are located at.

E.g. you have put one CI 2.1.2 system folder to /var/www/private/ci/2.1.2 then you would have

$system_path = '/var/www/private/ci/2.1.2';

in every index.php you want to access one common CodeIgniter set of core files.

This way only the application folder will be containing application-specific files.

I mainly want to use extends of core classes, libraries and helpers that i've written myself from a central location.

Like in my first post. The class MY_UI that extends UI.

Where do I put these files then?

Ah, sorry. Got your question wrong.

Hm, I think the easiest is using symlinks. That means, you have one location for your extended core-files and in every application you want to use them you just symlink the files. This way CI will kinda like "think" the files are there where they should be though they will be in one common location.
If you're on a windows machine you will simply create links but now symbolic links.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.