MVC programming in PHP [closed]

2

Good afternoon, I have a question about an exercise that I had taken in the course.

I need to make the updated text a hyperlink that goes back to hello word , creating a loop between them, ie (hyperlink) > updated text (hyperlink) > hello world (hyperlink). But I do not know how I'm going to do this loop. Thank you in advance!

Model

class Model
{
    public $text;

    public function __construct() 
    {
        $this->text = 'Hello world!';
    }       
}

View

class View
{
    private $model;
    private $controller;

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

    public function output() 
    {
        return '<a href="mvc.php?action=textclicked">' . $this->model->text . '</a>';
    }
}

Controller

class Controller
{

    private $model;

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

    public function textClicked()
    {
        $this->model->text = 'Texto Atualizado';
    }
}

Instances

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

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

echo $view->output();
    
asked by anonymous 22.02.2017 / 18:01

0 answers