当与 zend 库不在同一目录中时自动加载类
我决定不将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以创建一个库目录,其中包含指向实际实时共享代码的符号链接:
然后,您的路径中只需要 webroot/library 。
要处理版本更新,您只需更改符号链接以指向新安装:
You can create a single library directory, with symlinks to the actual live shared code:
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:
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.