php - 包括一个带有 PHP 的文件 - 避免找不到?
问题描述
我是 php 新手,我有两个文件,一个是我想保留我的类和大量代码的地方,另一个是我与一些 HTML 集成的地方。我的代码正在运行,但现在我收到错误消息:
PHP 致命错误:未捕获的错误:在 C:\MAMP\htdocs\index.view.php:84 中找不到类 'bardrink' 堆栈跟踪:> #0 {main} 在 C:\MAMP\htdocs\index.view 中抛出。第 84 行的 php
这是我的 index.php 文件:
<?php
class bardrink {
public $drink_name;
public $drink_desc;
public $drink_strength;
public $drink_price;
public function __construct($drink_name,$drink_desc,$drink_strength,$drink_price)
{
$this->drink_name = $drink_name;
$this->drink_desc = $drink_desc;
$this->drink_strength = $drink_strength;
$this->drink_price = $drink_price;
}
}
require 'index.view.php';
?>
在我的 index.view.php 我添加:
<?php
$barselection = [
new bardrink('Water','A light refreshing drink.',0,1),
new bardrink('Light Ale','A pale ale brewed locally.',2,4),
new bardrink('Mulled Wine','A warm festive wine, perfect for a chilly evening!',3,6),
new bardrink('Dark Ale','A strange frothy, dark liquid...',5,10)
];
var_dump($barselection)
?>
我在索引文件中需要 index.view.php,但我是否需要在我的视图文件中添加一个 require 才能使其工作?
解决方案
推荐阅读
- angular - @angular/material/autocomplete/typings/autocomplete-origin.d.ts 中的错误:类型“ElementRef”不是通用的
- javascript - 使用 React 更新值后无法获取存储值
- macos - 从 Darwin/XNU 版本中提取 macOS 版本名称
- android - 零持续时间的 Android 动画
- python - HTTP 错误 404:使用图形 API 抓取 Facebook 群组帖子时出现禁止错误
- css - 如何调整图像以适应 Bootstrap 中的 div?
- rust - 如果我不关心它的字段,我如何断言枚举是一个特定的变体?
- java - 将较长的 getTime() 分成 4 条短裤,实际上并不适用 Modbus
- laravel-5 - 具有动态语言环境的 Laravel 可翻译工厂播种
- c# - C#:使用 Python.Runtime 未找到