Zend 工具包含路径
是否可以在不访问 include_path 目录的情况下安装和使用 ZF(及其控制台工具)?我尝试将 ...Zend/library 目录添加到 include_path 但没有成功。
我是这样做的:
php -r 'set_include_path(get_include_path() . PATH_SEPARATOR . "/var/www/.../Zend/library")';
在 var_dump
上面函数的结果之后,它返回旧的 include_path 这应该意味着成功。但下次调用 get_include_path() 也返回了旧路径。
我还尝试设置环境变量:
ZF_INCLUDE_PATH_PREPEND="/var/www/.../Zend/library"
旧的 include_path 目录中有我们公司的框架,因此我无法(即使可以,我也不应该)将 ZF 库复制到那里。
我认为一个合适的框架不应该像 include_path 那样依赖于任何全局 PHP 设置。我认为应该可以在 ZF 内部配置文件中的某处设置包含路径。
编辑:
我将 set_include_path('/var/www/.../Zend/library')
添加到 zf.php 文件中,该工具停止抛出“错误的 include_path”错误。事实上,它阻止了打印任何输出。执行命令 zf create project test
时它什么也不做。未创建 ~/.zf 文件夹。
Is it possible to install and use ZF (+ its console tool) without access to include_path direcotory? I've tried adding the ...Zend/library direcotry into include_path but without success.
I did it this way:
php -r 'set_include_path(get_include_path() . PATH_SEPARATOR . "/var/www/.../Zend/library")';
After var_dump
ing result of the function above it returned old include_path which should mean success. But next call of get_include_path() returned the old path too.
I've also tried to set the environment variable:
ZF_INCLUDE_PATH_PREPEND="/var/www/.../Zend/library"
There is our company framework in the old include_path directory so I can't (even if I could I should't) copy there the ZF library.
I think a proper framework shouldn't rely on any global PHP settings as include_path is. I think it should be possible to set the include path somewhere in ZF internal configuration file.
edit:
I added set_include_path('/var/www/.../Zend/library')
into zf.php file and the tool stopped throwing 'wrong include_path' error. In fact it sopped printing any output. When executing command zf create project test
it does nothing. ~/.zf folder wasn't created.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您无法将 zf 库复制到某些“全局”包含路径(例如
/usr/share/php/
)中,您仍然可以将其复制到您的项目所在位置并启动zf< /code> 那里的工具。文件夹结构如下:
复制library下的
Zend
文件夹,以及bin
下的zf.sh
和zf.php
脚本code> 并将它们设置为可执行的chmod a+x zf.sh zf.php
(如果它们还不是可执行的)。接下来,如果您运行
/var/www/project/bin/zf.sh
,它将在 include_path 中查找 zf 文件,但如果不存在,它将转到上一个文件夹并转到进入library
文件夹。只有当在那里找不到 zf 库时,它才会因错误而终止。最后,创建一个新的 zf 项目非常简单:就是这样。哈:)
If you can't copy the zf library in some "global" include path, e.g.
/usr/share/php/
, you can still copy it where your project is and start thezf
tool from there. A folder structure like:Copy the
Zend
folder under library, and thezf.sh
andzf.php
scripts underbin
and set them to be executablechmod a+x zf.sh zf.php
if they are not already.Next, if you run
/var/www/project/bin/zf.sh
it'll look for zf files in the include_path, but if it's not there, it'll go up one folder and go into thelibrary
folder. Only if the zf library is not to be found there, it'll die with an error. In the end, creating a new zf project is simple as:That's it. HTH :)
使用 set/get include_path 函数只会在“请求”的生命周期内设置它,因此一旦命令/Web 请求完成,它就会恢复正常。至于设置本地副本的包含路径,您可以在您尝试过的环境变量中或在盒子上的
~/.zf
文件夹中执行此操作。那里有配置,并且有一个包含路径的设置。除此之外,您还可以将
php -r ...
中的内容添加到直接执行的 shell 脚本中,尽管这不是推荐的方式。Using he set/get include_path functions is only going to set it for the life of the "request" so it goes back to normal as soon as the command/web request finishes. As far as setting the include path for your local copy you can do that in an environment variable as you tried or in your
~/.zf
folder on the box. there are configs in there and there is a setting cor include path.Beyond that you could also ad something like what you had in the
php -r ...
to the shell script youre executing directly although this wouldnt be the recommended way.