htaccess 中的 php include_paths
我在各种不同的文件中有一些从不同地方调用的东西。我一直在尝试使用 $ROOT 变量,但是因为我要从几个不同的文件(index.php、view.php、admin/index.php 等)开始,并且没有引导程序(或其他任何文件)调用),我不能总是从 ajax 等调用的东西到达 $ROOT 。
如果我通过 htaccess 设置 include_path 有点像:
php_value include_path ".;C:\wamp\www\project\"
我假设不包括子目录,而且我还必须为我的文件所在的每个其他目录添加一行,即使它们位于 <代码>C:\wamp\www\project\components还是C:\wamp\www\project\model
?
我是否要添加新行或逗号?我在网上找不到任何使用 htaccess 设置包含多个路径的路径的示例...
或者有没有办法获取与我的 $ROOT 变量相关的所有内容并使用绝对路径,并以某种方式拥有每个文件,即使它们在不同的地方,引用那个特定的变量? (无需对应用程序中的所有文件进行批量更改?)这样做的好处是只需要在服务器更改/部署中更改文件,但我不知道如何开始!
谢谢 :)
I have a few things in various different files that get called from different places. I've been trying to use a $ROOT variable, but because I'm going from a few different files (index.php, view.php, admin/index.php etc) and don't have a bootstrap(or whatever that's called), I can't always get to $ROOT from things called by ajax etc..
if I set the include_path via htaccess somewhat like:
php_value include_path ".;C:\wamp\www\project\"
I assume that doesn't include subdirectories, and I would also have to add a line for each other directory where my files reside even if they're in C:\wamp\www\project\components
or C:\wamp\www\project\model
?
And do I add new lines or commas? I can't find any example online of using the htaccess to set include paths with multiple paths...
Alternately is there a way to get everything relating to my $ROOT variable and use absolute paths, and somehow have every file, even if they're in different places, reference that particular variable? (without having to make wholesale changes to all the files in the app?) That has the benefit of only needing to change on file in a server change/deployment, but I do not know how to start going about it!
thanks :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你为什么不尝试一下? (它确实包括子目录)
?您已经提供了一个:
路径为 '.'和 'C:\wamp\www\project\'
(顺便说一句,使用 '/' 作为目录分隔符是更好的做法 - 它可以避免对 UNIX 风格转义的混淆)
Why didn't you try it? (it does include sub dirs)
? You've already provided one:
The paths are '.' and 'C:\wamp\www\project\'
(BTW its better practice to use '/' as the dir seperator - it avoids confusion over unix style escaping)
在 Windows 环境中,您可以使用分号来分隔包含路径,如下所示:
但我不确定您为什么要这样做。添加子目录可能会导致文件命名冲突。如果有,C:\wamp\www\project\components\example.php 和 C:\wamp\www\project\models\example.php,在包含路径中包含这两个子目录,当您尝试包含任一文件。如果您的包含路径中已包含项目目录,则您已经可以使用相对路径调用其中的任何内容。例如:
这将包括 C:\wamp\www\project\components\example.php 并消除任何文件命名冲突的可能性。
In a Windows environment, you would use semicolons to separate include paths like so:
But I'm not sure why you'd want to do so. Adding sub-directories opens up the possibility of file naming collisions. If you have, C:\wamp\www\project\components\example.php and C:\wamp\www\project\models\example.php, including both sub-directories in your include path will create ambiguity when you try to include either file. If you already have the project directory in your include path, you can already call anything inside it using a relative path. For instance:
This would include C:\wamp\www\project\components\example.php and eliminate the chance of any file naming collisions.