当与 zend 库不在同一目录中时自动加载类

发布于 2024-09-24 08:56:24 字数 443 浏览 1 评论 0原文

我决定不将 Zend Framework 的副本放在每个应用程序的目录中,而是将其保留在服务器上的一个位置,并由我的所有网站使用该副本。但是,我希望我的应用程序的自定义类仍然位于应用程序文件夹中。所以文件夹结构有点像这样:

webroot
 |...library
 |     |......Zend
 |
 |...app1
 |     |.....Library
 |              |.......App1
 |
 |...app2
       |.....Library
                |.......App2

How can I get Zend Loader toautomatically find the classes in App1 and App2? (最好只更改 application.ini 或 bootstrap.php 中的某些内容)

I've decided that rather than have a copy of the Zend Framework in each application's directory, I'd like to keep it on one location on the server, with the one copy used by all my websites. However, I'd like my app's custom classes to still be within the application folder. So a folder structure a bit like this:

webroot
 |...library
 |     |......Zend
 |
 |...app1
 |     |.....Library
 |              |.......App1
 |
 |...app2
       |.....Library
                |.......App2

How can I get Zend Loader to automatically find the classes in App1 and App2? (preferably by just changing something in application.ini or bootstrap.php)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

萌辣 2024-10-01 08:56:24

您可以创建一个库目录,其中包含指向实际实时共享代码的符号链接:

webroot/library/Zend -> /path/to/Zend/library/Zend
webroot/library/App1 -> /path/to/App1/library/App1
webroot/library/App2 -> /path/to/App2/library/App2

然后,您的路径中只需要 webroot/library 。

要处理版本更新,您只需更改符号链接以指向新安装:

webroot/library/Zend -> /path/to/Zend-test/library/Zend

You can create a single library directory, with symlinks to the actual live shared code:

webroot/library/Zend -> /path/to/Zend/library/Zend
webroot/library/App1 -> /path/to/App1/library/App1
webroot/library/App2 -> /path/to/App2/library/App2

Then, you only need webroot/library in your path.

To handle version updates, you can simply change the symlink to point to a new install:

webroot/library/Zend -> /path/to/Zend-test/library/Zend
沫离伤花 2024-10-01 08:56:24

Zend Loader 将使用您的 php include_path查找要加载的文件。

只需将 webroot/library 添加到您的 include_path (您可以在 php.ini 或引导程序中执行此操作),自动加载器应该能够找到该框架。

如果您渴望拥有 Zend 的共享版本,您也可以使用 pear (http://pear.zfcampus. org/)来安装它,然后只要你将 include_path 设置为在你的 pear 目录(我的机器上的 /usr/share/php )中查找,那么你就可以开始了。

不过,我建议只对开发机器执行此操作,正如其他人所说,在生产时能够控制每个应用程序的 zend 版本是一个好主意。

The Zend Loader will use your php include_path to find files to load.

Simply add webroot/library to your include_path (which you can either do in php.ini or in your bootstrap) and the autoloader should be able to find the framework.

If you are keen to have a shared version of Zend you may as well just use pear (http://pear.zfcampus.org/) to install it and then as long as you have your include_path set to look in your pear dir ( /usr/share/php on my machine ) then you are good to go.

I would advise only to do this for dev machines though, as others have said it's a good idea to be able to control the versions of zend for each app when in production.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文