Pregunta

Actualmente estoy usando CodeIgniter para apoyar a un sitio, cuyo principal objetivo es mostrar varias mesas tablekit editables y manejar el AJAX que llega cuando se edita. Una especie de phpMyAdmin [muy] Lite. Tiene una serie de ayudantes básicos y los controladores, que se ejecutan los principales funcionamiento del sitio, mezclado con algunos controladores y ayudantes sitio específico.

Me gustaría reestructurar mi sitio para que pueda volver a utilizar el código base central en otro sitio. Sin embargo, todavía me gustaría ser tener algunas funciones del controlador por defecto y algunas funciones cutsom en el mismo controlador; es decir, en algún lugar de un archivo de sistema:

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

y en un sitio:

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

A continuación, en el otro sitio:

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

¿alguien tiene alguna orientación sobre cómo puedo hacer esto?

Gracias,

Lemiant

¿Fue útil?

Solución

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.

Otros consejos

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top