Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ Essa estrutura já está dockerizada, então basta ter o docker compose rodando

Primeiro basta clonar o repositório

`git clone bla bla bla`
`git clone https://github.com/digitalcollege-classes/php-oo`

Agora entre na pasta com o terminal
`cd setup-php-docker`
`cd php-oo`

E agora basta rodar o docker

`docker-compose up -d`

`composer dump`
Pronto,é sucesso!

Acesse o http://localhost:8080
29 changes: 21 additions & 8 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,28 @@
use App\Controller\HomeController;
use App\Controller\ErrorController;

return [
// url a ser acessada => [Controller, metodo]
'/' => [HomeController::class, 'index'],
$cursoController = CursoController::class;

$prefix = '/cursos';

$cursoRoutes = [
'listar',
'adicionar',
'editar',
'excluir'
];
Comment on lines +11 to +16
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

boa, gostei da abordagem, mas isso de certa forma nos restringe a precisar ter na url o mesmo nome do metodo, o que pode se tornar um problema de segurança.

Mas a ideia é essa, fazer sub arrays

Ah, vamos precisar mudar a logica tbm lá no index.php

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vou tentar mais um pouco da forma que eu tava pensando, fazer um array onde seria /cursos e dentro dele as outras rotas.


$cursosRoutes = [];

foreach ($cursoRoutes as $method) {
$cursosRoutes[$prefix . '/' . $method] = [$cursoController, $method];
}

$routes = [
'/' => [HomeController::class, 'index'],
'/erro-404' => [ErrorController::class, 'notFound'],
];

$NewRoutes = array_merge($routes, $cursosRoutes);

'/cursos/listar' => [CursoController::class, 'listar'],
'/cursos/adicionar' => [CursoController::class, 'add'],
'/cursos/editar' => [CursoController::class, 'editar'],
'/cursos/excluir' => [CursoController::class, 'excluir'],
];
return $NewRoutes;
2 changes: 2 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@

$url = $_SERVER['REQUEST_URI'];


if (false === isset($routes[$url])) {
header('location: /erro-404');
exit;
}


$controller = $routes[$url][0];
$method = $routes[$url][1];

Expand Down
2 changes: 1 addition & 1 deletion src/Controller/CursoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public function listar(): void
echo "Listar";
}

public function add(): void
public function adicionar(): void
{
echo "<marquee>Adicionar</marquee>";
}
Expand Down