Organizing Slim Framework Apps

I have recently fell in love with the Slim PHP Framework. If you haven’t checked it out, it’s worth taking a look. Of course its not for every project but for the simpler projects, it could be really useful.

One of the draw backs of the Slim framwork is it’s so simple that it doesnt really have a structure. Structure as in, there is no defined way to organized your app. So it’s up to you to build out a structure that works best for you and your project. Here is a break down of how I’ve recently been structuring my projects using Slim.

app
    views (templates)
        home.php
        login.php
        signup.php
    routes (routes organized into separate files)
        Users.php
        Home.php
    config (config files for local and production)
        app.php
        app.local.php
        database.php
        database.local.php
    models (for Laravel's Eloquent ORM)
        User.php
    
public
    css (Sass outputs to this dir)
    imgs
    js
    scss (all my .scss files)
    uploads (user uploaded content like icons)
    index.php (main file where slim is initiated)

vendor (This is created by composer)

My structure is heavaly influenced by Laravels structure. I even use the Laravel’s Eloquent ORM in my projects. I point Apache to the public directory, which keeps all the /app files safe from public access.