基本的MVC模式不起作用

时间:2014-05-01 13:20:51

标签: php oop

我运行了以下代码但没有发生任何事情

<?php
class Model
{
    public $string;

    public function __construct(){
        $this->string = 'MVC + PHP = Awesome, click here';
    }

}

class Controller
{
    private $model;

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

    public function clicked() {
        $this->model->string = 'Updated Data, thanks to MVC and PHP!';
    }
}

class View
{
    private $model;
    private $controller;

    public function __construct($controller,$model) {
        $this->controller = $controller;
        $this->model = $model;
    }

    public function output() {
        return '<p><a href="index.php?action=clicked"' . $this->model->string . "</a></p>";
    }
}


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



if (isset($_GET['action']) && !empty($_GET['action'])) {

    $controller->{$_GET['action']}();
}

echo $view->output();

?> 

我做错了什么?

1 个答案:

答案 0 :(得分:2)

此行中有拼写错误。<a>标记未关闭,这就是您无法看到文字的原因。

固定代码..

 public function output() {
        return '<p><a href="index.php?action=clicked">' . $this->model->string . "</a></p>";
    }