开发者

Break out shared model in code igniter applications

开发者 https://www.devze.com 2022-12-10 10:51 出处:网络
I\'m fairly new to code igniter and to php (coming from a java background). I want to create a model that\'s shared by three apps that may or may not run on the same machine.

I'm fairly new to code igniter and to php (coming from a java background).

I want to create a model that's shared by three apps that may or may not run on the same machine. So I want to keep the model classes portable to be shared by all three and easily handled by SCM systems.

So my thought was to do the following: If I have already broken the applications out into separate directories to share CI: /var/www/app1 /var/www/app1/models /var/www/app1/controllers ... /var/www/app2 /var/www/app3 /var/www/system

then create a shared folder to put the model in:

/var/www/share开发者_开发技巧d/models

Now I could either hack CI to look for the models there, or I could use symlinks, ie /var/www/app1/models -> ../shared/models /var/www/app2/models -> ../shared/models /var/www/app3/models -> ../shared/models

I'm new to the inner workings of PHP, so I'm thinking at minimum this will create a performance hit because the model files may be loaded up to 3 times (maybe 4), or at worse this'll just barf because there's 4 copies of files named the same thing.

Is this a bad idea? Is there a better way to do this?


Have you considered using Kohana instead? Kohana was initially a fork off CI but it has become an excellent framework on its own. The cascading filesystem feature that you can't find in any other web frameworks is really helpful to have multiple applications to share models/views/controllers/libraries/helpers etc.

Here is how I would do it in Kohana 2.x:

  • Upload the system and modules folders into a location outside of http root, e.g /apps/kohana/system and /apps/kohana/modules

  • Put the application folder somewhere nearby, e.g. /apps/kohana/applications/app1

  • Set up the /public_html/index.php to point to the 3 folders.

$kohana_application = '../apps/kohana/applications/app1';
$kohana_modules = '../apps/kohana/modules';
$kohana_system = '../apps/kohana/system';
  • Now just throw the model that you want to be shared among your apps into /apps/kohana/system/models/. Or if you want to restrict to only some apps, create a module for example /apps/kohana/modules/mymodule1 and configure those apps to use the module.
0

精彩评论

暂无评论...
验证码 换一张
取 消