thecodeholic / tc-php-mvc-core

103 stars 30 forks source link

Router parameter #1

Open aliberkyurtoglu opened 3 years ago

aliberkyurtoglu commented 3 years ago

Hey there,

user/update/1 or product/{:slug} or category/{:slug}/{:id}

When we define a route in the form of, we cannot access the '1' or 'slug' parameter other than using the $ _GET global. We send Request and Response classes as parameters to the controller. Likewise how can we send this '1' or 'slug' parameter?

khairnajdawi commented 3 years ago

It might be a year after the question, but it worth sharing the way I did it (using preg_match) first : index.php

second : Router.php

third : in controller add third parameter to your method as array public function getCustomerProfile(Request $request, Response $response, array $params){ $customer_id = $params[1]; // do not use 0 it will be the path // check if not null and do your thing }

virtual-designer commented 2 years ago

An update to the project was made by @thecodeholic. Check out #5

virtual-designer commented 2 years ago

I built my own PHP MVC framework; inspired by this project. Thank you @thecodeholic

thecodeholic commented 2 years ago

Amazing @virtual-designer. Love to hear such stories. Thank you

virtual-designer commented 2 years ago

Amazing @virtual-designer. Love to hear such stories. Thank you

Thanks sir! Here is my project link: https://github.com/onesoft-sudo/invention-project

thecodeholic commented 2 years ago

You got your first star from me. I will explore the project as soon as I have time. Cheers... Don't call me sir. Call me Zura. :)

virtual-designer commented 2 years ago

@thecodeholic Ok Zura. But you're a great man. You made my day :)

AngeArsene commented 5 months ago

I built my own PHP MVC framework; inspired by this project. Thank you @thecodeholic

I am trying to do that too. Its really cool to have such materials to work with