5 ms·
mysite.com/games/test_game instead of something like mysite.com/games?id=test_game Which would be the PHP solution? I fail to see what this has to
by Udo 13y ago
mysite.com/games/test_game
instead of something like
mysite.com/games?id=test_game
Which would be the PHP solution?
I fail to see what this has to do with using PHP or not. The entire question has a background untouched by any knowledge about either Node or PHP. The answer, however well and reasonably written, is about Node only. The title implies a discussion about why to prefer Node over PHP which is just not there.
Contrary to the title, the subject here is not PHP at all.
- locofacetwice 13y agoif this is his reason to choose node over php he is an idiot.
- efnx 13y agoThe person asking the question is mistaking get/post variables as a php language construct, instead of a web app construct.
- sparkygoblue 13y agoI noticed that as well. I think he was implying that the first URL structure isn't possible in PHP, which of course is not true.
- bdcravens 13y agoLikewise, you can pass and parse URL parameters in an Express app (or any framework for that matter) if so inclined
- adamors 13y agoOr just split the $_SERVER['REQUEST_URI'] by '/' and map the request to pages.
- kawsper 13y agoYes, but that can still be a bit complex. I have used https://github.com/chriso/klein.php https://github.com/chriso/klein.php prior for doing exactly this, but it was a long time ago, the codebase now seems a bit more advanced, and mature.
- krapp 13y agourl routing is one of those things about PHP frameworks I never really understood until I wrote my own. I think if you work with PHP, it's probably something you kind of should know how to do.
- geon 13y agoImho, '/' should be used to map a specific resource, like a file or a collection of objects in the database. URL arguments with '?' and '&' should specify a secondary "meta" mapping for things like sorting or filtering, that still acts on basically the same resource.
- ceol 13y agoThat's my opinion, as well. However, what about paginating things? A different page is a different set of the same type of object, so it's basically sorting and filtering, but you're returning different content. /posts/page/2 /posts?page=2 /posts?limit=25&offset=25 I like the third option because it allows the must functionality to the user if they so desire, but it kind of feels like a violation of the "only sorting and filtering" rule.
- thasmin 13y agoThe question seemed to be from a novice web developer.
- steveklabnik 13y agoMany PHP solutions rely on mod_rewrite to re-write URLs from the first to the second. Without those rewrite rules, you would get the second form.
- Udo 13y agoBecause PHP doesn't implement the web server itself but instead relies on Apache/Nginx/whatever, it has to use the info the server provides for routing. Once you configure the server to pass this information along, there is really not a lot of difference how routing takes place inside the web app. Of course, there are a lot of sites that use .htaccess to implement routing rules, but I'm not a huge fan of that. All things being equal, I believe just passing the virtual path to an /index.php endpoint is preferable - and it's pretty much what other languages and frameworks do in these cases as well.
- ErikAugust 13y agoHeh, agreed - and to think that the "PHP solution" is the latter automatically means the author doesn't know much about writing web apps in PHP. One line of mod_rewrite in an .htaccess file to rout everything to a 3 or 4 line controller script is all it takes. That being said - Node looks cool and I want to build something in it.
- 3minus1 13y agorta, he specifically mentions mod_rewrite