“移动”是什么意思?一个文件到包含路径列表中?

发布于 2024-10-31 20:27:22 字数 185 浏览 1 评论 0原文

在《Zend Framework,初学者指南》一书中;它说:

library/ 目录的内容应该移动到 PHP 中的某个位置“include 路径”列表。

我不明白。不包括引用特定位置中特定目录的路径保留值。是这个意思吗?或者我是否必须将文件夹移动到“包含路径”中已经提到的位置?

In the book Zend Framework, a Beginner's guide; it says:

The contents of the library/ directory should be moved to a location in your PHP “include
path” list.

I don't get it. Doesn't include path hold values that reference a certain directory in a certain location. Is that what it means? or do I litterally have to move the folder to a place that is already mentioned in "include path"?

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

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

发布评论

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

评论(2

还给你自由 2024-11-07 20:27:22

PHP 的 include_path与系统的 PATH 环境变量具有相同的用途:

“它定义了在查找要执行的命令时要搜索的目录列表。” (鲍勃·兰金,2011)。

正如 andre matos 之前的评论所指出的,您可以将库目录复制到系统的 PHP include_path 目录,也可以在 php.ini 文件中设置 PHP 路径配置指令“include_path”以将库目录包含为目录供 PHP 搜索。

无论您选择哪种方式,您都需要知道系统的 PHP include_path 目录。要查找系统的 PHP include_path 目录,您可以执行以下操作:

% php -i | grep include_path # assuming you are on Linux

- 或者,创建一个文件,例如“phpinfo.php”,然后添加以下 php 代码:

<?php phpinfo(); ?>

并通过 PHP 运行该文件,

% php phpinfo.php | grep include_path

- 或者,添加该文件例如,“phpinfo.php”,到您的 Web 服务器知道的目录,然后在 Web 浏览器中将其作为 URL 打开并搜索“include_path”。

例如,我的系统的 PHP include_path 位于: /usr/lib64/php

虽然最简单的方法可以说是将库目录复制到系统的 PHP include_path 目录(例如, /usr/lib64/php ),在系统的 php.ini 文件中设置 PHP 路径配置指令“include_path”也同样容易。

要在系统的 php.ini 文件中设置 PHP 路径配置指令“include_path”,请打开该文件并在“路径和目录”部分下找到“include_path”路径配置指令。它应该看起来像这样:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

删除“;”来自操作系统的 PHP 'include_path' 路径配置指令。

例如,如果您使用的是 Linux,则应该如下所示:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

然后将 PHP 'include_path' 路径配置指令设置为库目录,作为 PHP 搜索的目录。

例如,我将 ZendFramework 下载到

/usr/src/done/ZendFramework-1.11.4-minimal/

因此,我必须设置 PHP 'include_path' 配置指令以包含 ZendFramework 目录中的库目录,像这样:

include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"

系统 php.ini 文件中的“路径和目录”部分现在应该如下所示:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

让我解释一下我添加到 php.ini 文件中的 PHP“include_path”配置指令中的目录(如上所示) :

这 '。'是当前目录,'/usr/lib64/php'是系统的PHP include_path目录,'/usr/src/done/ZendFramework-1.11.4-minimal/library'是库目录的路径ZendFramework 目录。请注意,PHP 'include_path' 配置指令中列出的每个目录必须用 ':' 分隔(与系统 PATH 环境变量中列出的目录相同)。

将目录列表添加到 php.ini 文件中的 PHP“include_path”配置指令后,必须重新启动 Web 服务器以保存对 PHP 的更改。

例如,% sudo apachectl restart # 假设您正在使用Apache 作为您的 Web 服务器

希望这会有所帮助,

// Elliot。

PHP's include_path serves the same purpose as the system's PATH environment variable:

"It defines a list of directories to search through when looking for a command to execute." (Bob Rankin, 2011).

As the previous comment by andre matos indicated, you can either copy the library directory to your system's PHP include_path directory or you can set the PHP path configuration directive, 'include_path', in your php.ini file to include the library directory as a directory for PHP to search through.

Regardless of which way you choose, you need to know your system's PHP include_path directory. To find your system's PHP include_path directory, you can either do:

% php -i | grep include_path # assuming you are on Linux

-or, create a file, e.g., 'phpinfo.php', and add the following php code:

<?php phpinfo(); ?>

and run the file through PHP,

% php phpinfo.php | grep include_path

-or, alternatively, add the file e.g., 'phpinfo.php', to a directory your web server knows about, and open it as a url in a web browser and search for 'include_path.'

For example, my system's PHP include_path is at: /usr/lib64/php

Although the easiest way is arguably to just copy the library directory to your system's PHP include_path directory (e.g., /usr/lib64/php), it is also equivalently easy to set the PHP path configuration directive 'include_path' in your system's php.ini file.

To set the PHP path configuration directive 'include_path' in your system's php.ini file, open the file and locate the 'include_path' path configuration directive under the 'Paths and Directories' section. It should look something like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Remove the ';' from the PHP 'include_path' path configuration directive for your operating system.

e.g., If you are on Linux, it should look like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Then set the PHP 'include_path' path configuration directive to the library directory, as a directory for PHP to search through.

e.g., I downloaded the ZendFramework to

/usr/src/done/ZendFramework-1.11.4-minimal/

Therefore, I must set the PHP 'include_path' configuration directive to include the library directory within the ZendFramework directory, like this:

include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"

The 'Paths and Directories' section in the system's php.ini file, should now look like this:

;;;;;;;;;;;;;;;;;;;;;;;;;
; Paths and Directories ;
;;;;;;;;;;;;;;;;;;;;;;;;;

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
include_path = ".:/usr/lib64/php:/usr/src/done/ZendFramework-1.11.4-minimal/library"
;
; Windows: "\path1;\path2"
;include_path = ".;c:\php\includes"

Let me explain the directories I added to the PHP 'include_path' configuration directive in the php.ini file (shown above):

The '.' is the current directory, the '/usr/lib64/php' is the system's PHP include_path directory, and the '/usr/src/done/ZendFramework-1.11.4-minimal/library' is the path to the library directory in the ZendFramework directory. Note that each directory listed in the PHP 'include_path' configuration directive must be separated by a ':' (same as the directories listed in the system's PATH environment variable).

After you have added your list of directories to the PHP 'include_path" configuration directive in the php.ini file, you must restart your web server to save the changes to PHP.

e.g., % sudo apachectl restart # assumes you are using Apache as your web server

Hope this helps,

//. Elliot

小猫一只 2024-11-07 20:27:22

嗯...你可以两者都做。

将包含路径添加到您的 php.ini (搜索类似 include_path 的内容)

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;C:\PHP\pear;C:\PHP\otherfolder"

或将文件夹移动到已包含的某个路径(在执行前面的操作后您将知道哪些路径)搜索 php.ini)。

当您执行以下操作时:

<?php include 'file.php'; ?>

如果文件与您正在执行的脚本不在同一目录 (.) 中,则 php 将在 php.ini 上定义的包含路径中查找。

Well... You can do both.

Add an include path to your php.ini (search for something like include_path)

; UNIX: "/path1:/path2"
;include_path = ".:/php/includes"
;
; Windows: "\path1;\path2"
include_path = ".;C:\PHP\pear;C:\PHP\otherfolder"

Or move the folder to some path already included (that you will know which are after performing the previous search on php.ini).

When you do something like:

<?php include 'file.php'; ?>

If the file is not in the same directory (.) as the script you're executing php will look in the include paths defined on php.ini.

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