Slim Framework 4 Skeleton 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.

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
  • Update phpunit/phpunit requirement from ^9.5.26 to ^9.5.27

    Update phpunit/phpunit requirement from ^9.5.26 to ^9.5.27

    Updates the requirements on phpunit/phpunit to permit the latest version.

    Changelog

    Sourced from phpunit/phpunit's changelog.

    [9.5.27] - 2022-12-09

    Fixed

    • #5113: PHP error instead of PHPUnit error when trying to create test double for readonly class

    [9.5.26] - 2022-10-28

    Fixed

    • #5076: Test Runner does not warn about conflicting options

    [9.5.25] - 2022-09-25

    Added

    • #5042: Support Disjunctive Normal Form types

    Fixed

    • #4966: TestCase::assertSame() (and related exact comparisons) must compare float exactly

    [9.5.24] - 2022-08-30

    Added

    • #4931: Support null and false as stand-alone types
    • #4955: Support true as stand-alone type

    Fixed

    • #4913: Failed assert() should show a backtrace
    • #5012: Memory leak in ExceptionWrapper

    [9.5.23] - 2022-08-22

    Changed

    • #5033: Do not depend on phpspec/prophecy

    [9.5.22] - 2022-08-20

    Fixed

    • #5015: Ukraine banner unreadable on black background
    • #5020: PHPUnit 9 breaks loading of PSR-0/PEAR style classes
    • #5022: ExcludeList::addDirectory() does not work correctly

    [9.5.21] - 2022-06-19

    ... (truncated)

    Commits
    • a2bc7ff Prepare release
    • 1b09a9a Exclude source file with PHP 8.2 syntax
    • ac259bc Update Psalm baseline
    • 9e0968d Update ChangeLog
    • 8635ff9 Skip test on PHP < 8.2
    • faa1515 Implement logic to blocks readonly classes to be doubled.
    • 5c6e811 Merge branch '8.5' into 9.5
    • cc19735 Update tools
    • c5d3542 Assert that we have a DOMElement here
    • a653302 Document collected/iterated type using Psalm template
    • Additional commits viewable in compare view

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    dependencies 
    opened by dependabot[bot] 0
  • 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
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
[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components

Silex, a simple Web Framework WARNING: Silex is in maintenance mode only. Ends of life is set to June 2018. Read more on Symfony's blog. Silex is a PH

Silex 3.6k Dec 22, 2022
A resource-oriented micro PHP framework

Bullet Bullet is a resource-oriented micro PHP framework built around HTTP URIs. Bullet takes a unique functional-style approach to URL routing by par

Vance Lucas 415 Dec 27, 2022
🐺 Lightweight and easy to use framework for building web apps.

Wolff Web development made just right. Wolff is a ridiculously small and lightweight PHP framework, intended for those who want to build web applicati

Alejandro 216 Dec 8, 2022
Silly CLI micro-framework based on Symfony Console

currentMenu home Silly CLI micro-framework based on Symfony Console. Professional support for Silly is available via Tidelift Video introduction in fr

Matthieu Napoli 862 Dec 23, 2022
Lemon is php micro framework built for simple applications.

Lemon is simple micro framework that provides routing, etc.

Lemon 20 Dec 16, 2022
Blink is a micro web framework for building long-running and high performance services

Blink is a micro web framework for building long-running and high performance services, the design heavily inspired by Yii2 and Laravel. Blink aims to provide the most expressive and elegant API and try to make the experience of web development as pleasant as possible.

Jin Hu 837 Dec 18, 2022
TidyPHP is a micro php framework to build web applications

TidyPHP is a micro MVC PHP Framework made to understand how PHP Frameworks work behind the scense and build fast and tidy php web applications.

Amin 15 Jul 28, 2022
StackSync is a simple, lightweight and native fullstack PHP mini-framework.

StackSync is a fullstack PHP mini framework, with an MVC structure, custom API system with a Middleware and JWT authentication, components based views, flexible routing, PSR4 autoloading. Essential files generation (migrations, seeders, controllers and models) and other operations can be executed through custom commands.

Khomsi Adam 3 Jul 24, 2022
Larasymf - mini framework for medium sized projects based on laravel and symfony packages

Larasymf, PHP Framework Larasymf, as its says is a mini framework for medium sized projects based on laravel and symfony packages We have not yet writ

Claude Fassinou 6 Jul 3, 2022
PHP微服务框架即Micro Service Framework For PHP

Micro Service Framework For PHP PHP微服务框架即“Micro Service Framework For PHP”,是Camera360社区服务器端团队基于Swoole自主研发现代化的PHP协程服务框架,简称msf或者php-msf,是Swoole的工程级企业应用框

Camera360 1.8k Jan 5, 2023
Frankie - A frankenstein micro-framework for PHP

Frankie - A frankenstein micro-framework for PHP Features Frankie is a micro-framework focused on annotation. The goal is to use annotation in order t

null 19 Dec 10, 2020
ExEngine is an ultra lightweight micro-services framework for PHP 5.6+

ExEngine is an ultra lightweight micro-services framework for PHP 5.6+. Documentation Checkout the Wiki. Examples Click here to browse examples, also

linkfast.io 1 Nov 23, 2020
REST-like PHP micro-framework.

Phprest Description REST-like PHP micro-framework. It's based on the Proton (StackPhp compatible) micro-framework. Phprest gives you only the very bas

Phprest 312 Dec 30, 2022
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

Slim Framework 1.5k Dec 29, 2022
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
Slim Framework skeleton application with MVC Schema

Slim Framework skeleton application with MVC Schema

JingwenTian 9 Apr 29, 2021
Slim Framework 3 Skeleton Application + PagSeguro Lib

Slim Framework 3 Skeleton Application + PagSeguro Lib Aplicação simples para geração do Token para pagamentos no PagSeguro (método transparente) e env

Raí Siqueira 1 Feb 26, 2018
Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex Skeleton - a fully-functional Silex application that you can use as the skeleton for your new applications

Silex 789 Dec 5, 2022
This is a skeleton to quickly set up a new Slim 4 application.

Slim 4 Skeleton This is a skeleton to quickly set up a new Slim 4 application. Requirements PHP 7.4+ or 8.0+ MySQL 5.7+ or MariaDB Recommended Apache

Daniel Opitz 376 Jan 2, 2023
Aplicação criada com Slim Framework com objetivo de criar autenticação com JWT e aprender sobre o framework Slim

Slim JWT App Essa aplicação tem como foco o aprendizado do Framework Slim e também a utilização de JWT. Como rodar a Aplicação A aplicação está config

Nicolas Pereira 9 Oct 4, 2022