注意:尝试在/ opt / lampp / htdocs /中获取非对象的属性

时间:2017-09-22 04:13:19

标签: php

在尝试用PHP学习MVC时,我遇到了这个网站:https://r.je/mvc-in-php.html,我想测试它给出的一个例子。这是我收到的错误消息

 Notice: Trying to get property of non-object in /opt/lampp/htdocs/webs/train/mvc/helloWorld.php on line 19 

以下是代码:

<?php

  class Model {
  public $text;

  public function __constructor() {
    $this->text = "Hello World";
  }
 }

 class View {
 private $model;

 public function __constructor(Model $model) {
   $this->model = new Model();
 }

 public function output() {
   return "<h1>" . $this->model->text . "</h1><br>";
 }

 }

class Controller {
private $model;

public function __constructor(Model $model) {
  $this->model = $model;
}

}

$model = new Model();

$controller = new Controller($model);
$view = new View($model);

echo $view->output();

?>

请帮忙吗?

0 个答案:

没有答案