Welcome Guest, Not a member yet? Register   Sign In
COREPATH not used for core-classes
#1

[eluser]DIY_Peter[/eluser]
I definded an alternative corepath in index.php
Code:
// Path to the core folder
define('COREPATH','/www/html/apps/include/ci/');
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:
Code:
class MY_URI extends CI_URI
{
    public function __construct()
    {
        parent::__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 ?
#2

[eluser]DIY_Peter[/eluser]
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...
#3

[eluser]PhilTem[/eluser]
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...
#4

[eluser]DIY_Peter[/eluser]
Sorry, you're correct.

We used Phil Sturgeon’s autoload code

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 );
    endif;
}

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

Code:
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.
#5

[eluser]PhilTem[/eluser]
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

Code:
$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.
#6

[eluser]DIY_Peter[/eluser]
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?
#7

[eluser]PhilTem[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB