用PHP包含文件-避免找不到?

时间:2018-12-31 14:43:33

标签: php

我是php的新手,我有两个文件,一个要保留我的类和大部分代码,另一个要与一些HTML集成。我的代码正在运行,但是现在出现错误:

  

PHP致命错误:未捕获的错误:在C:\ MAMP \ htdocs \ index.view.php:84中找不到类'bardrink',堆栈跟踪:>在C:\ MAMP \ htdocs \ index中抛出了#0 {main} .view.php,第84行

这是我的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才能使其工作吗?

0 个答案:

没有答案