PatrickLouys / no-framework-tutorial

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

Help me with part 10 (Dynamic Pages) #57

Closed cesaribeiro closed 8 years ago

cesaribeiro commented 8 years ago

Hello! First of all, thank you very much for this tutorial, it's great! I'm stuck at Part 10, I've added the router for the slug ['GET', '/{slug}', ['Example\Controllers\Page', 'show']] and I've added the var_dump($params); on the Page.php file. But when I try to access http://localhost:8000/test but every time I get the Not Found apache error. What should I do?

Thank you!

PatrickLouys commented 8 years ago

If you are getting an apache error, you did not follow the tutorial because it uses the built-in server. Sounds like an htaccess issue, but you are on your own here.

If you need help otherwise please try room 11 on stackoverflow

cesaribeiro commented 8 years ago

Oh you're right, I'm sorry... I forgot about that... I started the server with php -S localhost:8000 and it's working perfectly now! Thank you!

cesaribeiro commented 8 years ago

Patrick, if you do not mind, can you point me in the direction of what should I do if I want to use apache for this project?

PatrickLouys commented 8 years ago

Haven't used Apache in at least 5 years, sorry. You need an URL rewrite that sends all requests to the front controller. Maybe look at how frameworks are doing it, they often come with a htaccess

michaelmillar commented 7 years ago

I came across a similar issue for anyone in the same situation, where the slug pages were throwing a 404. Just remember to put a .htaccess file in the public folder with something like:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>