Uma base de um mvc do zero feito para construir seus projetos rapidamente.
routes/web.php
$routes = new RouteCollection();
$routes->add("fruits", new Route("/fruits", ["controller"=>FruitsController::class, "method"=>"showFruits"]))
$routes->add("fruits-details", new Route("/fruits/:fruitName", ["controller"=>FruitsController::class, "method"=>"fruitDetails"]))
O constructor
Route
cria toda a estrutura de uma rota e passa paraRouteCollection
views/fruits.php
<!-- /fruits->pathname/fruitName -->
<a href="<?= $routes->getRoute('fruits')->pathname ?>/<?= $fruit->name ?>"><?= $fruit->name ?></a>
Controllers/FruitsController.php
class FruitsController extends Controller {
public function showFruits(RouteCollection $routes) {
return $this->view("fruits") // o mesmo que /views/fruits.php
}
}
Para ver mais detalhes de como a função
view
eredirect
funcionam, veja a classController
emControllers/Controller.php