开发者

PHP Application Structure/Pattern - 2 sites with shared libraries and assets

I'm having a bit of an application structure design dilemma.

I have created a web app that c开发者_StackOverflow中文版reates online surveys. It all works fine, but I would now like to create a new site that does different types of online surveys. This new site will be pretty much 95% similar in terms of layout, logic, functions, etc.

Rather than duplicate all the code from the current web app, I'd like the new app to share in the "fountain of knowledge" created by the current app - so to speak.

Can anyone enlighten me with their experiences of doing this sort of thing? Their best practices?

As a rough guide, I'm currently thinking of using symlinks for all the major logic files (library.php, functions.php, etc), and then deciding which logic to use based on which URL the user logged-in from.

Does that sound like a good or bad idea?

Would it be any better or worse to divide the whole system in to 3 sites, with the site in the middle containing all the common elements and logic? This middle site would have no independent use - it would be used from either of the 2 applications looking for functionality and assets, etc.

Any help and experience on this matter is very much appreciated indeed.

I'm very wary of going down a dead-end solution.

Kind Regards, Seb


Good solution if:

  • you host your website yourself and creating symlinks between differents virtual hosts is not a problem
  • you won't have to make significative changes between the 2 websites

But instead of using symlinks, I could take advantage of PHP's include_path directive and put the common libraries in this path. This way, just write your includes relative to this path, the files will be accessible from any site you want on the same server.

The second advantage of using include_path is you can bypass any open_basedir directives which wouldn't allow you to include files which are not in the same virtual host base dir.


This is how I'd do it...

  • Create a core library.
  • Create you 2 site directories.
  • Create site specific code folders in each site.
  • Create core library folders in each site that simlink to the main core library created.
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜