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

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

问题描述

我正在尝试使用 php 包含将一个 .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

使用 代码链接绝对没问题.

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

使用 <?PHP include dirname(__FILE__) .../../../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天全站免登陆