Codeigniter Shared Resources - Opinions Wanted

2019-07-31 09:24发布

I run multiple websites all running off of a single installation of CodeIgniter on my server (separate application directories and a single system directory). This has been working fabulously and I don't see any reason to change it at this point.

I find myself writing library classes to extend/override CI all of the time and many times if I find a bug or improve effeciency I have to go back to several websites to make the same adjustments at risk of a typo that breaks one of the websites. Because of this it requires that I change each file and then test that site for bugs.

I have been pondering a solution of using a single libraries directory in a central location and symlinking all of my websites to that central directory. Then when I make a file change it will immediately propagate to all of the downstream websites. It will still require that I test each one for errors, but I won't have to make the changes multiple times. Anything that is specific to a single website will either be a non-shared file (still in the linked directory just not used elsewhere) or can be put in a local helper.

Also, I keep separate 'system' directories by CI version so I can migrate my websites independently if necessary--this central libraries file would be attached to a specific version to reduce possible breaks.

Does anyone see potential issues or pitfalls from taking this approach? Has anyone accomplished this in another direction that I should consider?

Thanks in advance!

4条回答
beautiful°
2楼-- · 2019-07-31 10:04

I have a single system directory and separate application directories for my CI apps. In order to share libraries and some view templates between my apps, I have created a "Common" directory, in the same folder as the CI system and with the same structure as a regular app folder and used symlinks, but you can modify the Loader class so that it looks in the Common folder too. My setup looks something like this:

/var/CodeIgniter/
/var/Common/
/var/Common/config/
/var/Common/controllers/
...
/var/Common/libraries/
...
/var/www/someapp/
/var/www/someotherapp/
...
查看更多
在下西门庆
3楼-- · 2019-07-31 10:07

I'm not sure how you handle publishing your sites (assuming you actually do any of that), but I'd look into version control. For example, in SVN you can make external to another svn directory (or file) and then just update the current svn directory which grabs the external file. This approach gains one benefit from the others, which is when you modify the common library, the others aren't immediately affected. This prevents unwanted breaks before you have time to go test all the sites using the common library. You can then just update each site's folder whenever you are ready to test the changes. This is "more work", but it prevents code duplication AND unwanted breaks.

查看更多
冷血范
4楼-- · 2019-07-31 10:12

I wrote a MY_Loader to do exactly that.

http://ellislab.com/forums/viewthread/136321/

查看更多
乱世女痞
5楼-- · 2019-07-31 10:17

I think this actually makes sense :] Go for it. Even on official CodeIgniter page, they mention it's possible.

Also, I don't see one reason why there should be any problem.

Edit: they touch the problem of multiple sites here: http://codeigniter.com/user_guide/general/managing_apps.html

also:

http://codeigniter.com/wiki/Multiple_Applications/
http://www.exclusivetutorials.com/setting-multiple-websites-in-codeigniter-installation/
How to Handle Multiple Projects in CodeIgniter?
http://codeigniter.com/forums/viewthread/56436/

查看更多
登录 后发表回答