Tonight I decided to check out the Slim Framework. I heard about it at Tek13, and had been wanting to see what it was like.
The first thing I had to do was understand Composer. I started reading on the Composer website, and quickly had it installed in a test folder. The instructions were pretty simple and easy to follow. The only thing I found mildly confusing is that they say they support Windows, OSX, and Linux, but then only give instructions for Linux and Windows. It was pretty intuitive to figure out that I needed to use the Linux instructions for OSX, but it doesn’t actually say that anywhere, so it took me a moment to decide to just try it.
Once I understood how Composer was installed, and what it does, I went back to the Slim instructions and copied the “Hello World” code:
<?php
require 'vendor/autoload.php';
$app = new \Slim\Slim();
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});
$app->run();
Here, once again, the instructions fall short for the beginner. I went to the site in my browser at http://127.0.0.1:8888/ and got a 404 page.

Ok, now what?
I started commenting out lines of code to see where the error started, and it seemed that the first 2 lines were the only ones not causing an error.
I decided do some searching on Google, and found enough information to figure out that the URL was not correct. Because the route on line 6 says “/hello/:name”, it is looking specifically for http://127.0.0.1:8888/index.php/hello/kenny (or any other name of course)
Once I tried that path, it worked! The lightbulb lit, and I “got it”.
My first Slim application! Albeit simple, but it worked!
Tagged on: php slimframework