PatrickLouys / no-framework-tutorial

A small tutorial to show how to create a PHP application without a framework.
MIT License
1.53k stars 186 forks source link

404 - Page not found #65

Closed TheRealDatafan closed 6 years ago

TheRealDatafan commented 6 years ago

I'm working on the router and despite lot's of troubleshooting efforts I can't get the Dispatcher to find the route.

If I do a var_dump on $dispatcher I get the following which I think is ok: object(FastRoute\Dispatcher\GroupCountBased)#12 (2) { ["staticRouteMap":protected]=> array(1) { ["GET"]=> array(1) { ["/"]=> array(2) { [0]=> string(32) "NOFRAMEWORK\Controllers\Homepage" [1]=> string(4) "show" } } } ["variableRouteData":protected]=> array(0) { } } array(1) { [0]=> int(0) }

I believe it has to do with this line, I'm not sure it's being passed what it's expecting. $routeInfo = $dispatcher->dispatch($request->getMethod(), $request->getPath()); $request->getMethod() returns GET $request->getPath() returns /public/

Do those values seem correct?

I am obviously learning here, and appreciate any help. Thank You

TheRealDatafan commented 6 years ago

I just figured it out. The /public/ path was incorrect. I changed this line as follows and it works:

$routeInfo = $dispatcher->dispatch("$request->getMethod()", $request->getPath());

$routeInfo = $dispatcher->dispatch("GET", "/");

Just have to figure out why $request->getPath() is returning /public/ now. It's coming from here: $request = new \Http\HttpRequest($_GET, $_POST, $_COOKIE, $_FILES, $_SERVER);

randyao commented 6 years ago

Good to hear you resolved this issue. How is the build going now?

On Mon, Apr 16, 2018, 10:40 PM Jim Marquardt notifications@github.com wrote:

I just figured it out. The /public/ path was incorrect. I changed this line as follows and it works: $routeInfo = $dispatcher->dispatch("$request->getMethod()", $request->getPath()); $routeInfo = $dispatcher->dispatch("GET", "/");

Just have to figure out why $request->getPath() is returning /public/ now.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/PatrickLouys/no-framework-tutorial/issues/65#issuecomment-381826681, or mute the thread https://github.com/notifications/unsubscribe-auth/AWHlv8cdxFC8XOBFkjyHt-UN1Xv13kOnks5tpWQsgaJpZM4TXkiu .

ivanfranco502 commented 4 years ago

I was having the same issue, you shouldn't change anything in the code. Instead, you should run php -S localhost:8000 in the public directory (I was running it in the root directory). I hope this help someone else.