首页 > 解决方案 > 使用包含的基本帮助

问题描述

我有一个基本问题,这确实是一个入门问题,文档没有帮助!我的 html 根目录中有一个 index.php,其中包含以下内容

<html>
    <head>
        <title>PHP Spike</title>
    </head>
    <body>
        <?php           
            include __DIR__ . 'testInclude/data.php';
            $dataObj = new testClass;
            $data = $dataObj->GetData();
            echo "$data" 
        ?>
    </body>
</html>

在名为 testInclude 的子文件夹中,我有一个名为 data.php 的文件,其中包含

<?php
class testClass
{
    public function GetData()
    {
        return "Hello World";

    }
}
?>

主页正在呈现(标题显示,如果我添加 html 它可以工作,但否则,我什么也得不到。有人可以指出我做错了什么吗?

谢谢

Ĵ

标签: phpinclude

解决方案


更改此行:

include __DIR__ . 'testInclude/data.php';

对此:

include __DIR__ . '/testInclude/data.php';

推荐阅读