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 它可以工作,但否则,我什么也得不到。有人可以指出我做错了什么吗?
谢谢
Ĵ
解决方案
更改此行:
include __DIR__ . 'testInclude/data.php';
对此:
include __DIR__ . '/testInclude/data.php';
推荐阅读
- php - 为什么分配的数据不会立即更改为模板中的分配值?
- angular - Angular 应用程序不会以独立模式启动
- python - scipy 插入从文件导入的 2D 数据
- haskell - 为什么 (.) 地图有这种类型?
- hockeyapp - 通过 api 下载曲棍球应用程序
- r - 滚动 xts 时间序列
- cordova - 在 phonegap 中通过 ajax 附加远程 html 内容时图像损坏
- java - JUnit 预期异常未按预期工作
- apache-kafka - 来自两个分区的 Kafka 消费者
- entity-framework - EF Core - 为所有属性定义自定义列映射策略