PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Manage routes with Slim framework and MAMP

 March 14, 2022     mamp, php, slim     No comments   

Issue

It seems that there is a conflict between MAMP and Slim framework on my environment.
I am trying to learn Slim, and I have this weird situation where I can create a route for '/', but impossible to do it for '/contact'.

$app->get('/', \App\Controllers\PagesController::class . ':home');
$app->get('/contact', \App\Controllers\PagesController::class . ':getContact');

Slim seems to catch the / route, but when I type http://localhost:8888/contact/ in my browser Slim doesn't catch the request, I have a 404...

I tried to create a real "contact" folder with an index.html file inside, and of course then it works... it displays the index.html


Solution

You need to route all requests to the index.php file. Mamp is looking for a directory structure that does not exist until you create it, as you did.

Create a .htaccess file in the your app's root folder. and insert the following:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]

if you are just learning php and slim then I recommend ditching MAMP and just using the integrated PHP server. From your project's folder, Kick off the server with the following CLI command: PHP -S localhost:3000



Answered By - Scriptonomy
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing