corrigindo rotas
This commit is contained in:
17
app/controllers/Controller.php
Normal file
17
app/controllers/Controller.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
namespace app\controllers;
|
||||
use League\Plates\Engine;
|
||||
|
||||
class Controller{
|
||||
public static function view(string $view, array $data = []){
|
||||
|
||||
$viewsPath = dirname(__FILE__,2)."/views";
|
||||
|
||||
if(!file_exists($viewsPath . DIRECTORY_SEPARATOR . $view.".php")){
|
||||
throw new \Exception("A view {$view} não existe");
|
||||
}
|
||||
|
||||
$templates = new Engine($viewsPath);
|
||||
echo $templates-> render($view,$data);
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,7 @@
|
||||
namespace app\controllers;
|
||||
|
||||
class HomeController{
|
||||
|
||||
public function index(){
|
||||
return Controller::view("home");
|
||||
}
|
||||
}
|
||||
@@ -2,5 +2,11 @@
|
||||
namespace app\controllers;
|
||||
|
||||
class LoginController{
|
||||
public function index(){
|
||||
return Controller::view("login");
|
||||
}
|
||||
|
||||
public function store(){
|
||||
var_dump('store do login');
|
||||
}
|
||||
}
|
||||
3
app/views/home.php
Normal file
3
app/views/home.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php $this->layout("master");?>
|
||||
|
||||
<h1>Home</h1>
|
||||
3
app/views/login.php
Normal file
3
app/views/login.php
Normal file
@@ -0,0 +1,3 @@
|
||||
<?php $this->layout("master");?>
|
||||
|
||||
<h1>Login</h1>
|
||||
11
app/views/master.php
Normal file
11
app/views/master.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<?=$this->section('content')?>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user