使用 includes 的基本帮助
Basic help using includes
我有一个基本问题,这确实是一个入门问题,文档没有帮助!
我的 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 它可以工作,但除此之外,我什么也得不到。
有人可以指出我做错了什么吗?
谢谢
J
更改此行:
include __DIR__ . 'testInclude/data.php';
为此:
include __DIR__ . '/testInclude/data.php';
我有一个基本问题,这确实是一个入门问题,文档没有帮助! 我的 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 它可以工作,但除此之外,我什么也得不到。 有人可以指出我做错了什么吗?
谢谢
J
更改此行:
include __DIR__ . 'testInclude/data.php';
为此:
include __DIR__ . '/testInclude/data.php';