0

While trying to learn about MVC in PHP, I came across this site : https://r.je/mvc-in-php.html, where I wanted to test one of the examples it gave. And this is the error message I get

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

Here's the code:

<?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();

?>

Please any help?

tereško
  • 58,060
  • 25
  • 98
  • 150
  • The View class' Constructor should not assign the instance member model to a new Model object. It should assign it to the model that was passed in. I still don't see why this would cause an error from the given code though. – Khaines0625 Sep 22 '17 at 04:40
  • It's okay, I just figured it out: I messed out with the __constructor() method. it's rather spelled __construct(). Thanks. – daniel Graham Sep 22 '17 at 04:54

0 Answers0