Use this skeleton application to quickly setup and start working on a new Slim Framework 4 application

Overview

Slim Framework 4 Skeleton Application

Coverage Status

Use this skeleton application to quickly setup and start working on a new Slim Framework 4 application. This application uses the latest Slim 4 with Slim PSR-7 implementation and PHP-DI container implementation. It also uses the Monolog logger.

This skeleton application was built for Composer. This makes setting up a new Slim Framework application quick and easy.

Install the Application

Run this command from the directory in which you want to install your new Slim Framework application. You will require PHP 7.4 or newer.

composer create-project slim/slim-skeleton [my-app-name]

Replace [my-app-name] with the desired directory name for your new application. You'll want to:

  • Point your virtual host document root to your new application's public/ directory.
  • Ensure logs/ is web writable.

To run the application in development, you can run these commands

cd [my-app-name]
composer start

Or you can use docker-compose to run the app with docker, so you can run these commands:

cd [my-app-name]
docker-compose up -d

After that, open http://localhost:8080 in your browser.

Run this command in the application directory to run the test suite

composer test

That's it! Now go build something cool.

Comments
  • Status code 405

    Status code 405

    When this project is run from netbeans and wamp server, I get the following error. { "statusCode": 405, "error": { "type": "NOT_ALLOWED", "description": "Method not allowed. Must be one of: OPTIONS" } }

    Please help in solving this. Thank you very much.

    opened by jagadishnallappa 18
  • what does the container callback param `$c` mean in dependencies.php?

    what does the container callback param `$c` mean in dependencies.php?

    Hi,I am new fish about slim, I cloned the Slim-Skeleton to my computer,and it works fine.But when I check the code,I am confused about the

     $container['renderer'] = function ($c) {
        $settings = $c->get('settings')['renderer'];
        return new Slim\Views\PhpRenderer($settings['template_path']);
    };
    

    in the dependencies.php ? what does the param $c mean?

    opened by shanezhiu 13
  • Monolog usage appears to break PrettyExceptions

    Monolog usage appears to break PrettyExceptions

    I caused some sort of error in my app (go figure) and the pretty exceptions page through a wobbly:

    jose@mactaku:~/Sites/seatgeek/sg-android-artifacts  $ curl -X POST --data-urlencode  "payload@payload" http://localhost/seatgeek/sg-android-artifacts/public/travisci
    <br />
    <font size='1'><table class='xdebug-error xe-fatal-error' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
    <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Fatal error: Call to a member function error() on a non-object in /Users/jose/Sites/seatgeek/sg-android-artifacts/vendor/slim/slim/Slim/Middleware/PrettyExceptions.php on line <i>71</i></th></tr>
    <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
    <tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
    <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0002</td><td bgcolor='#eeeeec' align='right'>239272</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='/Users/jose/Sites/seatgeek/sg-android-artifacts/public/index.php' bgcolor='#eeeeec'>../index.php<b>:</b>0</td></tr>
    <tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0081</td><td bgcolor='#eeeeec' align='right'>494576</td><td bgcolor='#eeeeec'>Slim\Slim->run(  )</td><td title='/Users/jose/Sites/seatgeek/sg-android-artifacts/public/index.php' bgcolor='#eeeeec'>../index.php<b>:</b>36</td></tr>
    <tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0089</td><td bgcolor='#eeeeec' align='right'>523200</td><td bgcolor='#eeeeec'>Slim\Middleware\PrettyExceptions->call(  )</td><td title='/Users/jose/Sites/seatgeek/sg-android-artifacts/vendor/slim/slim/Slim/Slim.php' bgcolor='#eeeeec'>../Slim.php<b>:</b>1254</td></tr>
    </table></font>
    

    Relevant middleware code:

    public function call()
    {
        try {
            $this->next->call();
        } catch (\Exception $e) {
            $log = $this->app->getLog(); // Force Slim to append log to env if not already
            $env = $this->app->environment();
            $env['slim.log']->error($e);
            $this->app->contentType('text/html');
            $this->app->response()->status(500);
            $this->app->response()->body($this->renderBody($env, $e));
        }
    }
    
    wontfix 
    opened by josegonzalez 11
  • Multiple exceptions result in invalid JSON

    Multiple exceptions result in invalid JSON

    When multiple exceptions are thrown and then handled by the HttpErrorHandler, the resulting response contains invalid JSON, for example:

    {
        "statusCode": 500,
        "error": {
            "type": "SERVER_ERROR",
            "description": "DateTime::__construct(): Failed to parse time string (1569885313) at position 8 (1): Unexpected character"
        }
    }{
        "statusCode": 500,
        "error": {
            "type": "SERVER_ERROR",
            "description": "ERROR: DateTime::__construct(): Failed to parse time string (1569885313) at position 8 (1): Unexpected character on line 117 in file C:\\xxxx\\vendor\\paragonie\\paseto\\src\\JsonToken.php."
        }
    }
    
    opened by chocolatkey 9
  • Slim Skeleton shows 500 error right after setup

    Slim Skeleton shows 500 error right after setup

    Right after composer create-project slim/slim-skeleton myslimsite, I ran composer start and went to localhost:8080/users/which returned a json object as below.

    {
        "statusCode": 404,
        "error": {
            "type": "RESOURCE_NOT_FOUND",
            "description": "Not found."
        }
    }{
        "statusCode": 500,
        "error": {
            "type": "SERVER_ERROR",
            "description": "ERROR: ob_clean(): failed to delete buffer. No buffer to delete on line 28 in file \/Volumes\/WD Mac\/work\/test\/slim-project\/myslimsite\/src\/Application\/ResponseEmitter\/ResponseEmitter.php."
        }
    }
    

    Any help on this much appreciated.

    opened by gopumon 9
  • No input file specified.

    No input file specified.

    I have setup as described in this tutorial, but still i am getting No input file specified when i try hit this url http://aami.noqplz.com/App/public/Hello the above url shows

    **Internal Server Error

    The server encountered an internal error or misconfiguration and was unable to complete your request.

    Please contact the server administrator and inform them of the time the error occurred, and the actions you performed just before this error.

    More information about this error may be available in the server error log.**

    but this http://aami.noqplz.com/App/public/ Url working fine.

    and this url http://aami.noqplz.com/App/public/index.php/Hello/Devendra Shows No input file specified. Please help me. i am in problem.

    opened by droidwithme 9
  • Fatal error on composer start

    Fatal error on composer start

    Internal PHP server composer start throws fatal error on the request:

    > php -S localhost:8080 -t public public/index.php
    [Sun Jan 28 19:32:59 2018] PHP Warning:  Unknown: failed to open stream: No such file or directory in Unknown on line 0
    [Sun Jan 28 19:32:59 2018] PHP Fatal error:  Unknown: Failed opening required '/home/skoro/Projects/php/test/public/public/index.php' (include_path='.:/usr/share/php') in Unknown on line 0
    
    opened by skoro 9
  • Example for beginners on how to call vars from $this when looking at values from settings.php

    Example for beginners on how to call vars from $this when looking at values from settings.php

    Running into issue calling values that are stored in the $this object..

    The how-to for configuring the database connections was followed from: https://arjunphp.com/how-to-connect-to-mysql-database-in-slim-framework-4/

    If I follow the example exactly, it works within the route.php.

    However I am attempting to call the PDO class information stored inside $this down in the Actions and running into trouble. I see that the $this object contains the values using "get_object_vars", however I cannot figure out how to call $this correctly to retrieve the values.

    $test = $this->get(PDO::class);
    returns:
    "Call to undefined method…\NewPollerAction::get()"
    

    In the dump it LOOKS like I should be able to get those values (I think)

    -- logger stuff removed for clarity --
     [db] => Array ( [driver] => mysql [host] => 192.168.15.250 [username] => randouser [database] => event [password] => XXXX [charset] => utf8mb4 [collation] => utf8mb4_unicode_ci [flags] => Array ( [12] => [3] => 2 [20] => 1 [19] => 2 ) ) ) )
    

    I would have guessed this would work, but does not: $this->db, and I would have expected an array return back with all my db values

    So my question is, how the heck do I use $this and retrieve what I need out of it correctly? I figure if I can see it, I should be able to grab it AFAIK. Google shows me really simple examples, but with all the added use statements, it is messy in my object and cannot figure out what I need to be calling as far as $this->???->db, or $this->???->(however many levels down it is)->db

    I have autowire set in my use statement but it does not like the get() even with autowire in place, so I am a confused n00b.. :)

    opened by Guyverix 8
  • Request an example of a POST inside the skeleton

    Request an example of a POST inside the skeleton

    I have been learning a lot by using your skeleton, however I am having some trouble with POST.

    The GET makes sense, but since I am not a real developer, I am having a tough time making a POST without the application barfing on my ignorance. Any chance that a POST in the routes can be added with a simple/complete example?

    opened by Guyverix 8
  • Docker Compose Bug?

    Docker Compose Bug?

    in docker-compose.yml the line:

    command: php -S 0.0.0.0:8080 -t public index.php
    

    Was throwing errors for me:

    bash-3.2$ docker-compose up
    Recreating myfirstslimphpapp_slim_1 ...
    Recreating myfirstslimphpapp_slim_1 ... done
    Attaching to myfirstslimphpapp_slim_1
    slim_1  | PHP 7.2.2 Development Server started at Thu Feb  8 17:13:57 2018
    
    screen shot 2018-02-08 at 12 14 27

    I had to change it to:

    command: php -S 0.0.0.0:8080 -t public
    
    bash-3.2$ docker-compose up
    Recreating myfirstslimphpapp_slim_1 ...
    Recreating myfirstslimphpapp_slim_1 ... done
    Attaching to myfirstslimphpapp_slim_1
    slim_1  | PHP 7.2.2 Development Server started at Thu Feb  8 17:14:53 2018
    
    screen shot 2018-02-08 at 12 15 32

    Am I doing something wrong or is this a bug that should be fixed in the project?

    opened by svpernova09 8
  • update docker-compose.yml

    update docker-compose.yml

    I needed that change to make docker-compose up work. Otherwise i got: Fatal error: Unknown: Failed opening required '/var/www/public/public/index.php' (include_path='.:/usr/local/lib/php') in Unknown on line 0

    opened by tomtomsen 8
  • Little refactor using early return

    Little refactor using early return

    Hi guys, thanks for this awesome micro framework.

    I made this little refactor using early return to reduce cyclomatic complexity in this class. In my personal project I made unit test for this class, if you want too, feel free to talk me that I provide a test here too.

    opened by joubertredrat 0
  • Guide for Slim skeleton

    Guide for Slim skeleton

    Hi there,

    The current guide learn us how to make apps with Slim but not using Slim skeleton.

    Since they are several ways to make the same thing, I think you should add doc/guide for Slim skeleton too. I suggest you to create a tab so we can choose which is our preferred way to build a Slim app: normal or via skeleton.

    Thanks.

    opened by abelardolg 0
  • Phpstan 1.8 level 7 compliance

    Phpstan 1.8 level 7 compliance

    I love Slimphp skeleton template have used for years, but am always making tweaks to make it phpstan compliant. Here's some changes (as safe as I can make them) so it's compatible with level 7.

    opened by milescook 1
  • Wamp server setup to make this skeleton work.

    Wamp server setup to make this skeleton work.

    Hi,

    Sorry if this isn't your concern. But a complete tutorial on how to setup wamp server to get this skeleton working would be greatly helpful for people trying to run slim 4 or this skeleton on wamp server and encountering the frustrating 405 error.

    {
        "statusCode": 405,
        "error": {
            "type": "NOT_ALLOWED",
            "description": "Method not allowed. Must be one of: OPTIONS"
        }
    }
    

    Please post a tutorial specifically for wamp server on the windows machine. Thank you very much.

    opened by jagadishnallappa 2
Releases(4.5.0)
Owner
Slim Framework
Slim is a PHP micro framework that helps you quickly write simple yet powerful web applications and APIs.
Slim Framework
Slim Framework 4 Skeleton Application

Slim Framework 4 Skeleton Application Use this skeleton application to quickly setup and start working on a new Slim Framework 4 application. This app

Cleonildo Soares Guimaraes Junior 5 Nov 21, 2021
SPA Skeleton with Mithril.js and Slim Framework

A single-page application (SPA) skeleton based on Mithril.js and Slim Framework 4 trying to use good practices

tebe 5 Oct 23, 2022
⚡️ This package provides a wonderful PHP skeleton to start building your next package idea.

This package provides a wonderful PHP Skeleton to start building your next package idea. Requires PHP 8.0+ ⚡️ Create your package using Composer: comp

Nuno Maduro 383 Dec 20, 2022
Simple skeleton for the PHP Slim framework

Simple skeleton for the PHP Slim framework

Andrew S Erwin 2 Nov 13, 2021
This repository is pre-configured, clean and empty skeleton for creating a new projects using Kraken Framework.

Kraken Application Skeleton Note: This repository contains pre-configured application skeleton for fast creation of new projects with Kraken Framework

Kraken 79 Aug 6, 2022
A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify

A simple and clean boilerplate to start a new SPA project with authentication and more features from fortify. Its like the little sister of Jetstream, but as SPA.

Tobias Schulz 11 Dec 30, 2022
This is Slim 3 API skeleton project for Composer

Slim 3 API skeleton This is Slim 3 API skeleton project for Composer. Project uses Zend Table Gateway and Phinx for database operations, Monolog for l

Mika Tuupola 304 Dec 28, 2022
Start a new Laravel 8 project with the AdminLTE template installed.

AdminLTE template Laravel 8 package Start a new Laravel 8 project with the AdminLTE template installed. Installation Create database. Clone repository

Mairo Rodrigues 12 Dec 21, 2022
Opinionated way to start a new Laravel project.

Laravel Boilerplate The way I start new Laravel projects. Why? I just got tired of repeating the same things over and over. I made this repository pub

Benjamin Crozat 0 Mar 18, 2022
Easily start new projects using FukigenMedia's starterpack.

Fukigen Filament Starterpack Easily start new projects using FukigenMedia's starterpack. Usually, many of us are confused about where to start a new p

Fukigen Media 8 Oct 9, 2022
A skeleton WordPress project to be used as a base for new WordPress projects.

BoxUK WordPress Project Skeleton A base WordPress project from Box UK to get you up and running quickly. Installation Create a new project with compos

Box UK 33 Dec 14, 2022
Symfony React Blank is a blank symfony and react project, use this template to start your app using Symfony as an backend api and React as a frontend library.

Symfony React Blank Symfony React Blank is a blank symfony and react project, use this template to start your app using Symfony as an backend api and

Antoine Kingue 2 Nov 5, 2021
A skeleton application using the Zend Framework MVC

This is a skeleton application using the Zend Framework MVC layer and module systems. This application is meant to be used as a starting place for those looking to get their feet wet with Zend Framework.

Zend Framework 1.5k Dec 15, 2022
This template repository is a boilerplate setup for a PHP application

PHP_Docker Repository Template What is this ? This template repository is a boilerplate setup for a PHP application. Its current version ships with PH

Kevin Richard 0 Jul 16, 2022
Laravel 8 boilerplate in docker-compose with Treafik and SSL setup and github workflow ready for CI/CD pipeline

Laravel8 boilerplate Laravel 8 boilerplate in docker-compose with Treafik and SSL setup with .github workflow ready To start the containers in prod en

Tej Dahal 5 Jul 9, 2022
Laravel Quick-Start - a boilerplate for Laravel Application with typical packages preinstalled and configured

Laravel Quickstart is a boilerplate for Laravel Application with typical packages preinstalled and configured to extend a full-fledged application. We tried to make it as minimal as possible.

Vijay Goswami 18 Sep 8, 2022
A script to help setup Laravel project with common packages and configurations

About Snap Snap allow developer to create scaffold Laravel project. Installation Clone this repository in your user home directory. cd ~ git clone htt

Nasrul Hazim Bin Mohamad 3 Jan 4, 2022
Start your application with Hamtaro.

Hamtaro framework About Technologies Controllers Components Commands Front-end development Getting Started About Hamtaro is the new web framework for

Phil'dy Jocelyn Belcou 1 May 12, 2022