Skip to content

Getting Started

System Requirements

  • PHP >= 5.4.0 (including >= 7.0.0)
  • PHP must have the openssl module to use encrypted cookies.

Installation

The following example clones the Skinny repository from GitHub using command line git. You can allso download a .zip file and extract it into your project directory.

Download

Let's create a directory for your project and call it play. Clone Skinny into a sub-directory named skinny. ('$>' represents your shell prompt)

$> mkdir play
$> cd play
$> git clone git@github.com:ghaecker/Slim2Skinny.git skinny

Hello World

Assuming you successfully cloned Skinny into a directory called skinny, navigate to your installation directory. Create a document root and front-end controller.

$> cd skinny
$> mkdir public
$> touch public/index.php

With your favorite text editor, put the following content in public/index.php:

<?php

// 1. Set up autoloading
require_once './skinny/Skinny/Skinny.php';
\Skinny\Skinny::registerAutoloader();

// 2. Instantiate a Skinny application:
$app = \Skinny\Skinny::newInstance();

// 3. Define a HTTP GET route:
$app->get('/hello(/:name)', function ($name = 'World') {
    echo "Hello, $name";
});

// 4. Run the Skinny application:
$app->run();

Note: the demo app shows an alternative way to set up autoloading.

Try It!

While still in the installation directory, run this command:

$> php -S 127.0.0.1:8000 -t ./public

Open a web browser and type 127.0.0.1:8000/hello in the address bar. Try 127.0.0.1:8000/hello/Sam, too. There ya go... easy as pie.

See also Web Server Setup Tips.