PHPackages                             enygma/slim-app-skeleton - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. enygma/slim-app-skeleton

ActiveLibrary[Framework](/categories/framework)

enygma/slim-app-skeleton
========================

A skeleton of a Slim application (with extras)

0.3(9y ago)216MITPHP

Since Oct 28Pushed 8y agoCompare

[ Source](https://github.com/enygma/slim-app-skeleton)[ Packagist](https://packagist.org/packages/enygma/slim-app-skeleton)[ RSS](/packages/enygma-slim-app-skeleton/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependencies (8)Versions (4)Used By (0)

Slim Application Skeleton
=========================

[](#slim-application-skeleton)

This project is a basic skeleton of a Slim application that includes:

- Controller support
- Templating via [Twig](http://twig.sensiolabs.org/) views (including layouts)
- A basic file structure for an MVC application
- Database migrations with [Phinx](https://phinx.org/)
- [Eloquent](https://laravel.com/docs/5.3/eloquent) for working with database models and tables
- Simple encryption using the [Defuse PHP Encryption](https://github.com/defuse/php-encryption) library
- Session security improvements (including encryption)

Installation:
-------------

[](#installation)

There are two ways you can install the project and get it up and running: *automated and manual*

### Automated

[](#automated)

To use the automated method, execute the `setup.sh` script in the root directory of the project:

```
chmod +x setup.sh
./setup.sh

```

This will ask you a series of questions to set up the application and create the `.env` configuration file to match

### Manual

[](#manual)

The manual process goes through the same flow, you just have to do things by hand. Here's the basic steps:

1. Copy the `.env.example` file to `.env`
2. Use your favorite text editor to open the file and update the settings inside to match your configuration
3. Copy over the `phinx.yml.example` file to `phinx.yml`
4. Open it and, in the `development` section update it with your database configuration information (matching what's in `.env`)
5. Use this command to generate an encryption key:

```
php -r 'require_once "vendor/autoload.php"; $key = Defuse\Crypto\Key::createNewRandomKey(); echo $key->saveToAsciiSafeString();'

```

and replace the `ENC_KEY` value with the result 6. Create a `tmp/` directory and `chmod` it:

```
mkdir tmp;
chmod -R 777 tmp;

```

Hosting the site
----------------

[](#hosting-the-site)

### Built-in PHP server

[](#built-in-php-server)

The simplest way to use the skeleton is to just serve it locally with the built-in PHP server. To do this, clone the repository into a directory and `cd public/`. Once in the public directory, use this command to host the site:

```
php -S localhost:8080

```

This will make the site available on `http://localhost:8080` - if you hit that URL in a browser the

### Hosting with Apache

[](#hosting-with-apache)

You can also set up a virtual host to serve the site from an Apache instance. Ensure that `mod_rewrite` is enabled and point your web server at the `public/` directory as the document root:

```

	ServerName slim-app.localhost
	DocumentRoot /var/www/slim-app/public
	ErrorLog "/var/log/www/slim-app-error_log"

```

Be sure to replace the hostname and `ErrorLog` path for your environment.

Using the Project
-----------------

[](#using-the-project)

Below is information about actually using the project and working with routes, controllers and views.

### Adding a new route

[](#adding-a-new-route)

The default installation comes with an example of a simple "index" route you can use for reference but here's a guide to setting up a new controller and all its matching pieces:

#### Create the controller class

[](#create-the-controller-class)

The controller class should be created in `App\Controller` with the naming convention `*Controller.php`. So, if you're wanting to add some routes for "Foo" the file should be `App\Controller\FooController.php` and contain the following:

```
