与zend库不在同一目录中时自动加载类 [英] Autoloading classes when not in same directory as zend library

查看:68
本文介绍了与zend库不在同一目录中时自动加载类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

如何让Zend Loader自动在App1和App2中找到类? (最好仅更改application.ini或bootstrap.php中的内容)

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)

推荐答案

Zend Loader将使用您的php

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

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

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.

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

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.

不过,我只建议对开发人员计算机这样做,因为其他人说,在生产中能够控制每个应用程序的zend版本是个好主意.

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.

这篇关于与zend库不在同一目录中时自动加载类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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