From fc66f9258599c285a4623b71685732e630dff121 Mon Sep 17 00:00:00 2001 From: Zura Sekhniashvili Date: Mon, 21 Feb 2022 10:19:08 +0400 Subject: [PATCH 1/3] Working on url params --- controllers/SiteController.php | 9 ++++++++- public/index.php | 14 +++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/controllers/SiteController.php b/controllers/SiteController.php index bb4ee04..c3430bc 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -85,4 +85,11 @@ public function profile() { return $this->render('profile'); } -} \ No newline at end of file + + public function profileWithId(Request $request) + { + echo '
';
+        var_dump($request->getBody());
+        echo '
'; + } +} diff --git a/public/index.php b/public/index.php index 7557b49..b8d7a51 100644 --- a/public/index.php +++ b/public/index.php @@ -24,18 +24,26 @@ $app = new Application(dirname(__DIR__), $config); -$app->on(Application::EVENT_BEFORE_REQUEST, function(){ +/*$app->on(Application::EVENT_BEFORE_REQUEST, function(){ echo "Before request from second installation"; -}); +});*/ $app->router->get('/', [SiteController::class, 'home']); $app->router->get('/register', [SiteController::class, 'register']); $app->router->post('/register', [SiteController::class, 'register']); $app->router->get('/login', [SiteController::class, 'login']); +$app->router->get('/login/{id}', [SiteController::class, 'login']); $app->router->post('/login', [SiteController::class, 'login']); $app->router->get('/logout', [SiteController::class, 'logout']); $app->router->get('/contact', [SiteController::class, 'contact']); $app->router->get('/about', [AboutController::class, 'index']); $app->router->get('/profile', [SiteController::class, 'profile']); +// /profile/{id} +// /profile/13 +// \/profile\/\w+ -$app->run(); \ No newline at end of file +// /profile/{id}/zura +// /profile/12/zura + +// /{id} +$app->run(); From 2737906075a61d06756c1f1dae25ff8aefd6bc59 Mon Sep 17 00:00:00 2001 From: Zura Sekhniashvili Date: Tue, 22 Feb 2022 10:50:59 +0400 Subject: [PATCH 2/3] Implement possibility to get route params from URL --- controllers/SiteController.php | 3 +++ public/index.php | 1 + 2 files changed, 4 insertions(+) diff --git a/controllers/SiteController.php b/controllers/SiteController.php index c3430bc..fdb79b4 100644 --- a/controllers/SiteController.php +++ b/controllers/SiteController.php @@ -38,6 +38,9 @@ public function home() public function login(Request $request) { + echo '
';
+        var_dump($request->getBody(), $request->getRouteParam('id'));
+        echo '
'; $loginForm = new LoginForm(); if ($request->getMethod() === 'post') { $loginForm->loadData($request->getBody()); diff --git a/public/index.php b/public/index.php index 9e281b2..8572ddf 100644 --- a/public/index.php +++ b/public/index.php @@ -38,6 +38,7 @@ $app->router->get('/contact', [SiteController::class, 'contact']); $app->router->get('/about', [AboutController::class, 'index']); $app->router->get('/profile', [SiteController::class, 'profile']); +$app->router->get('/profile/{id:\d+}/{username}', [SiteController::class, 'login']); // /profile/{id} // /profile/13 // \/profile\/\w+ From 95341ce6721153e75016e574de91d82800a54bf2 Mon Sep 17 00:00:00 2001 From: Zura Sekhniashvili Date: Tue, 22 Feb 2022 11:07:13 +0400 Subject: [PATCH 3/3] Update core to version 1.0.5 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index ff794d0..12a7b15 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,6 @@ }, "require": { "vlucas/phpdotenv": "^5.0", - "thecodeholic/php-mvc-core": "^v1.0.4" + "thecodeholic/php-mvc-core": "^v1.0.5" } }