diff --git a/App/Controllers/Posts.php b/App/Controllers/Posts.php index d42ed5c..1e0cb7e 100644 --- a/App/Controllers/Posts.php +++ b/App/Controllers/Posts.php @@ -9,7 +9,7 @@ class Posts return true; } - public function new() + public function entry() { echo "You can entry new data here."; // Nanti di replace sama twig view ke App\Views\Data\new_pengumuman.html return true; diff --git a/Core/Router.php b/Core/Router.php index d2d1f1a..062c328 100644 --- a/Core/Router.php +++ b/Core/Router.php @@ -33,6 +33,7 @@ class Router public function match($url) { $url = htmlspecialchars($url); + $url = substr_replace($url, '', 0, 1); foreach ($this->routes as $route => $params) { if (preg_match($route, $url, $matches)) { diff --git a/_tests/unit/RouterTest.php b/_tests/unit/RouterTest.php index 5d0115f..2464832 100644 --- a/_tests/unit/RouterTest.php +++ b/_tests/unit/RouterTest.php @@ -6,6 +6,8 @@ class RouterTest extends \PHPUnit\Framework\TestCase /** * Data provider for matchingRouteSuccess * + * Contains: route, params, $_SERVER['REQUEST_URI'], expected_params + * * @return array */ public function routeProvider() @@ -13,15 +15,15 @@ class RouterTest extends \PHPUnit\Framework\TestCase return [ [ '', - ['controller' => 'home', 'action' => 'index'], + ['controller' => 'posts', 'action' => 'index'], '', - ['controller' => 'home', 'action' => 'index'] + ['controller' => 'posts', 'action' => 'index'] ], [ '{controller}/{action}', [], - 'posts/new', - ['controller' => 'posts', 'action' => 'new'] + 'posts/entry', + ['controller' => 'posts', 'action' => 'entry'] ], [ '{controller}/{action}/{id:\d+}', diff --git a/public/index.php b/public/index.php index c5cca77..81e03fd 100644 --- a/public/index.php +++ b/public/index.php @@ -1,9 +1,19 @@ add('', ['controller' => 'Data', 'action' => 'index']); +$router = new Core\Router(); + +$router->add('', ['controller' => 'posts', 'action' => 'index']); $router->add('{controller}/{action}'); $router->add('{controller}/{action}/{id:\d+}'); +$router->add('{action}', ['controller' => 'home']); -$url = $_SERVER['QUERY_STRING']; +$url = $_SERVER['REQUEST_URI']; $router->dispatch($url);