سؤال

I am currently using CodeIgniter to support one site, whose main purpose is to display multiple editable tablekit tables, and handle the AJAX that arrives when you edit them. A kind of PHPMyAdmin [VERY] Lite. It has a number of core helpers and controllers, which run the main workings of the site, mixed in with some site specific controllers and helpers.

I would like to restructure my site so that I can reuse the core code-base in another site. However, I would still like to be have some default controller functions and some cutsom functions in the same controller; i.e. in a system file somewhere:

class My_core extends Controller{
    /*
      Lots of base functions
    */
}

and on one site:

class site_1 extends My_Core{
    /*
       Site specific functions
    */
}

Then on the other site:

class site_2 extends My_Core{
    /*
       Site specific functions
    */
}

Does anyone have any guidance on how I can do this?

Thanks,

Lemiant

هل كانت مفيدة؟

المحلول

If you are using CodeIgniter 2.0 you can achieve most of this with with packages. They will let you load helpers, libraries and models from anywhere, so in each application simply configure a package to be loaded from that shared folder.

As for core libraries (which MY_Controller will be) you will have to implement your own __autoload() function:

http://php.net/manual/en/language.oop5.autoload.php

You can put an autoloader at the bottom of config.php. As long as it is checking the correct folders (local first, then the shared folder structure) it should all work pretty nicely.

نصائح أخرى

I don't know if this is still helpful to you but heres what I've done.

say I have 2 websites, palladium.com and osmium.com.

my file tree looks like this

/var/www/system/ (the CI system folder)

/var/www/palladium/application
/var/www/palladium/public/index.php

/var/www/osmium/application
/var/www/osmium/public/index.php

inside those index.php files are lines that define where /system/ is stored. I've got that set to

$system_folder = "../../system";

Now inside /var/www/system/libraries i have a file named MY_TestClass

<?php

class MY_TestClass {
    public function MY_TestClass() {
        echo "this is a test of the emergency broadcast system";
    }
}

From anywhere inside BOTH palladium.com and osmium.com i can call

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

and "this is a test of the emergency broadcast system" will show up.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top