在多个 PHP 站点之间共享代码 [英] Share Code between multiple PHP sites

查看:23
本文介绍了在多个 PHP 站点之间共享代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好.我发现一些问题似乎与我提出的问题相同,但似乎没有一个答案对我有用.基本上,我有一些通用的 PHP 文件(主要是类,但有些不是),我希望多个 PHP 站点可以使用它们.

Good evening. I found a few questions that seemed to ask the same thing I am asking, but none of the answers seems to work for me. Basically, I have a few generic PHP files (mostly classes, but some are not) that I want to be usuable by multiple PHP sites.

这是我的文件夹结构示例:

Here is an example of my folder structure:

站点 A 根C:\个人\网站\站点A

Site A Root C:\Personal\WebSites\SiteA

站点 B 根C:\个人\网站\站点B

Site B Root C:\Personal\WebSites\SiteB

共享代码C:\个人\网站\共享

Shared Code C:\Personal\WebSites\Shared

从站点 A 我尝试使用 include("../Shared/foo.php") 来访问文件,但这不起作用.我有一种感觉,这是因为该文件夹超出了 SiteA 的站点根文件夹.有没有办法简单地包含共享目录中的文件?我无法想象这是一种罕见的做法,但我就是想不通.

From Site A I tried using include("../Shared/foo.php") to reach the files, but this did not work. I have a feeling this is due to the folder being beyond the site root folder of SiteA. Is there a way to simply include files from the Shared directory? I can't imagine this is an uncommon practice, but I just can't figure it out.

顺便说一句,如果重要的话,我在 Windows 7 上通过 IIS(通过 FastCGI)使用 PHP 5.2.14.最终,我会将这些站点迁移到 Linux/Apache 托管,因此我更愿意使用任何解决方案.

BTW, I am using PHP 5.2.14 through IIS (via FastCGI) on Windows 7 if that matters. Eventually, I will be moving these sites to Linux/Apache hosting, so I would prefer any solution to work with either.

谢谢!!

推荐答案

在您的 php.ini 中,您可以将目录添加到 include_path,然后它们就会包含文件.

In your php.ini you can add directories to the include_path, and them include files from then.

"C:\Personal\Websites\Shared;"

如果您将这样的字符串附加到已经存在的 include_path 中,您可以执行 include 'specialDir\Class.php' wherespecialDirspecialDir 中的一个目录/code>共享`.

If you append a string like that to the already existing include_path you can do include 'specialDir\Class.php' wherespecialDiris a directory inShared`.

这篇关于在多个 PHP 站点之间共享代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆