包含在图书馆中 [英] Includes in libraries
问题描述
一个相当简单的问题:
我有一个库A,它依赖于库B和C.
目前我有:
<?php
include(A.inc.php);
include(" B.inc) .php");
包括(C.inc.php);
?>
.. ..在我的HTML中。
这需要改为:
<?php
include(" ; ../ A.inc.php);
包括(../ B.inc.php);
包括(../ C.inc.php);
?>
....如果我从目录树的更深处调用它。
我不想在我的HTML中包含很多内容。我想写一下:
<?php
包括(A.inc.php);
? >
....并将其他包含在A.inc.php中。文件。
但是如果我把:
包含(B.inc.php);
包括(C.inc.php);
....在图书馆中,使用时不包含文件:
<?php
包括(../ A.inc.php);
?>
....在一个HTML文件中与根相距一段距离。
我不想连接绝对路径。
我*可以*传递../&;作为一个方法参数 - 但是
似乎是一团糟。
解决这个问题的最佳方法是什么?
-
__________
| im | yler http://timtyler.org/ ti*@tt1lock.org 删除锁定以回复。
A fairly simple question:
I have a library A which depends on library B and C.
Currently I have:
<?php
include("A.inc.php");
include("B.inc.php");
include("C.inc.php");
?>
....in my HTML.
This needs changing to:
<?php
include("../A.inc.php");
include("../B.inc.php");
include("../C.inc.php");
?>
....if I call it from deeper in the directory tree.
I don''t want lots of includes in my HTML. I want to write:
<?php
include("A.inc.php");
?>
....and to have the other includes in the "A.inc.php" file.
However if I put:
include("B.inc.php");
include("C.inc.php");
....in the library, it doesn''t fild the files when included using:
<?php
include("../A.inc.php");
?>
....in an HTML file some distance from the root.
I don''t want to wire absolute paths in.
I *could* pass the "../" in as a method parameter - but that
seems like a total mess.
What is the best way to resolve this issue?
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
推荐答案
Tim Tyler写道:
Tim Tyler wrote:
一个相当简单的问题:
我有一个库A,它依赖于库B和C 。
目前我有:
<?php
include(" ;.inc.php");
include(" B) .inc.php");
包含(C.inc.php);
?>
...在我的HTML中。
<这需要改为:
<?php
include(&..; A.inc.php");
include(&... B.inc.php);
包括(../ C.inc.php);
?>
...如果我从迪伊目录树中的每个。
我不想在我的HTML中包含很多内容。我想写一下:
<?php
include(" ;.inc.php");
?>
..并且将另一个包括在A.inc.php中。文件。
但是,如果我把:
include(B.inc.php);
include(C.inc.php) ;
...在库中,使用时不包含文件:
<?php
include(&.. /A.inc.php");
?>
...在距离根目录一定距离的HTML文件中。
我不是想要连接绝对路径。
我*可以*传递../&;作为一个方法参数 - 但这似乎是一团糟。
解决这个问题的最佳方法是什么?
A fairly simple question:
I have a library A which depends on library B and C.
Currently I have:
<?php
include("A.inc.php");
include("B.inc.php");
include("C.inc.php");
?>
...in my HTML.
This needs changing to:
<?php
include("../A.inc.php");
include("../B.inc.php");
include("../C.inc.php");
?>
...if I call it from deeper in the directory tree.
I don''t want lots of includes in my HTML. I want to write:
<?php
include("A.inc.php");
?>
...and to have the other includes in the "A.inc.php" file.
However if I put:
include("B.inc.php");
include("C.inc.php");
...in the library, it doesn''t fild the files when included using:
<?php
include("../A.inc.php");
?>
...in an HTML file some distance from the root.
I don''t want to wire absolute paths in.
I *could* pass the "../" in as a method parameter - but that
seems like a total mess.
What is the best way to resolve this issue?
最好的办法是将所有库放在一个目录中并将其添加到php.ini中的include_path中。
如果你看错了常量_FILE_,在A.inc将
指向A.inc的完整路径(我认为)。
Best idea is to put all your libraries in a single directory and add it
to include_path in php.ini.
Failing that you could look at the constant _FILE_ which, in A.inc will
point to the full path of A.inc (I think).
蒂姆泰勒< ti*@tt1lock.org>写道或引用:
[snip]
Tim Tyler <ti*@tt1lock.org> wrote or quoted:
[snip]
但是如果我把:
include(" B。 inc.php);
包含(C.inc.php);
...在库中,它不会在文件中输入包括使用:
<?php
include(&..; A.inc.php");
?>
。 ..在距离根部一定距离的HTML文件中。
我不想把绝对路径连接起来。
我*可以*传递.. /"作为一个方法参数 - 但这似乎是一团糟。
解决这个问题的最佳方法是什么?
However if I put:
include("B.inc.php");
include("C.inc.php");
...in the library, it doesn''t fi[n]d the files when included using:
<?php
include("../A.inc.php");
?>
...in an HTML file some distance from the root.
I don''t want to wire absolute paths in.
I *could* pass the "../" in as a method parameter - but that
seems like a total mess.
What is the best way to resolve this issue?
前置
Prepending
DOCUMENT_ROOT似乎是一种可能的解决方案。
它不是一个理想的解决方案 - 因为它也阻碍了可移植性, />
通过在带有absoulte元素的路径中连接。
即如果我想移动库文件相对于
webserver '的文档根,然后他们需要重写。
-
__________
| im | yler http://timtyler.org/ ti * @ tt1lock。组织删除锁定以回复。
DOCUMENT_ROOT seems like a possible resolution.
It''s not an ideal solution - since it too hinders portability,
by wiring in an path with an absoulte element.
i.e. if I ever want to move the library files relative to the
webserver''s document root, then they would need rewriting.
--
__________
|im |yler http://timtyler.org/ ti*@tt1lock.org Remove lock to reply.
这篇关于包含在图书馆中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!