Witam
Uczę się MVC mam napisany router i teraz przyszedł czas na widok i controller, wiem że na początku musiałbym napisać coś w tym controllerze ale na razie chciałbym uzyskać odpowiedz na pytanie, więc tak mam zmienną $this->test= 'abc', dołączam widok ale w tym widoku nie mogę się odwołać do zmiennej.
class Router
{
private $router;
private $controller;
public function __construct()
{
$this->router = strtolower($_GET['router']);
$this->router = rtrim($this->router, "/");
$this->router = explode("/", $this->router);
$this->controller = ucfirst($this->router[0]);
if($this->controller === "Index.php") {
$this->controller = "Index";
}
$file = 'controller/'.$this->controller.'.php';
if(file_exists($file)) {
require_once($file);
$openClass = new $this->controller($this->router);
} else {
echo "Nie można wczytać ścieżki do pliku";
}
}
}
class Controller
{
protected $view;
public function __construct()
{
$this->view = new View();
}
}
class View
{
public function render(string $path = null, string $name)
{
if($path) {
require_once('view/' . $path . '/' . $name . '.php');
} else {
require_once('view/'. $name . '.php');
}
}
}
class Index extends Controller
{
public $test;
public function __construct($action)
{
parent::__construct();
echo $action[1];
$this->test = 'a';
$this->view->render("test", "test");
}
}
<html>
<head>
<title>Test</title>
</head>
<body>
<h2><?php echo $this->test; ?></h2>
</body>
</html>
błąd to Notice: Undefined property: View::$test in D:\XAMPP\htdocs\Testy\MVC\view\test\test.php on line 6