2
Good afternoon, I’m having a doubt in an exercise that had passed me in the course.
I need to get the updated text is a hyperlink that goes back to the hello word, creating a loop between them, ie: hello world (hyperlink) > updated text (hyperlink) > hello world (hyperlink). But I don’t know how I’m going to make this loop. Thanks 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();
Entire programming here: http://collabedit.com/a49ft
– Tuna000