__DIR__不适用于PHP包括 [英] __DIR__ not working for a php include

查看:64
本文介绍了__DIR__不适用于PHP包括的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用php include将一个.php文件链接到另一个.结构是这样的:

I am trying to use php includes to link one .php file to another. The structure is this:

ROOT
¦
+---templates
¦   ¦
¦   +---footer.php
¦
¦
+---main
    ¦
    +---maps
        ¦
        +---uk
            ¦
            +---map.php

使用<?PHP包括"../../../templates/navbar.php";?> 该代码链接绝对正确.

Using <?PHP include "../../../templates/navbar.php"; ?> the code links absolutely fine.

使用<?PHP include dirname(__ FILE__)."../../../templates/navbar.php";?>

<?PHP包含__DIR__."../../../templates/navbar.php";?> 绝对不会给我任何帮助.我想念什么?谢谢.

or <?PHP include __DIR__ . "../../../templates/navbar.php"; ?> gets me absolutely nothing. What am I missing? Thanks.

推荐答案

__ DIR__在目录名称中不包含结尾的/,因此<?PHP包括__DIR__."/../../../templates/navbar.php";?> 是您所需要的.

__DIR__ doesn't include the trailing / in directory name, so <?PHP include __DIR__ . "/../../../templates/navbar.php"; ?> is what you need.

这篇关于__DIR__不适用于PHP包括的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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