Quantcast
Channel: Slim Framework – Rob Allen's DevNotes
Browsing all 38 articles
Browse latest View live

Routing to a controller with Slim 2

In a couple of projects that I've written using Slim Framework 2, I've found it beneficial to organise my code into controllers with injected dependencies; probably because that's how I'm used to...

View Article


Run Slim 2 from the command line

If you need to run a Slim Framework 2 application from the command line then you need a separate script from your web-facing index.php. Let's call it bin/run.php: bin/run.php: #!/usr/bin/env php...

View Article


Logging errors in Slim 3

Slim Framework 3 is being actively developed at the moment and has a number of changes in it, including the use of the Pimple DI container and an overhaul of pretty much everything else! In this post,...

View Article

Using Zend\Config with a Slim app

Sometimes you need more configuration flexibility for your application than a single array. In these situations, I use the Zend\Config component which I install via composer: composer require...

View Article

Image may be NSFW.
Clik here to view.

A Slim3 Skeleton

Warning Slim 3 is currently under active development. Expect BC breaks! I'm creating a number of projects in Slim 3 (which is currently under development) at the moment in order test things out and...

View Article


Accessing services in Slim 3

One of the changes between Slim Framework 2 and 3 is that the application singleton has gone. In Slim 2, you could do this: $app = \Slim\Slim::getInstance(); // do something with $app In general, you...

View Article

First beta of Slim Framework 3

Last night, I tagged beta 1 of Slim Framework 3! This is a significant upgrade to v2 with a number of changes that you can read on the Slim blog. For me, the two key features that I'm most excited...

View Article

Replacing Pimple in a Slim 3 application

One feature of Slim 3 is that the DI container is loosely coupled to the core framework. This is done in two ways: The App composes the container instance rather than extending from it. Internally, App...

View Article


Using abstract factories with Slim 3

In my Slim 3 skeleton, I chose to put each action into its own class so that its dependencies are injected into the constructor. We then register each action with the DI Container like this:...

View Article


Image may be NSFW.
Clik here to view.

Slim-Csrf with Slim 3

In addition to the core Slim framework, we also ship a number of add-ons that are useful for specific types of problems. One of these is Slim-Csrf which provides CSRF protection. This is middleware...

View Article

Image may be NSFW.
Clik here to view.

Improved error handling in Slim 3 RC1

From RC1 of Slim 3, we have improved our error handling. We've always had error handling for HTML so that when an exception occurs, you get a nice error page that looks like this: However, if you're...

View Article

Slim 3.0 RC2 Released

I released Slim 3 RC 2 today after a longer than expected gap from RC1. The gap was caused by two things: Real LifeTM was busy for all the core team members People test RCs, but not betas! Obviously,...

View Article

Running Phan against Slim 3

Having installed Phan, I decided to use it against the upcoming Slim 3 codebase. Phan needs a list of files to scan, and the place I started was with Lorna's article on Generating a file list for Phan....

View Article


PSR-7 file uploads in Slim 3

Handling file uploads in Slim 3 is reasonably easy as it uses the PSR-7 Request object, so let's take a look. The easiest way to get a Slim framework project up and running is to use the Slim-Skeleton...

View Article

Image may be NSFW.
Clik here to view.

Improved error handling in Slim 3.2.0

We released Slim 3.2.0 yesterday which includes a number of minor bug fixes since 3.1.0 and also a few nice improvements around the way we handle errors. Writing to the error log Slim has a simple...

View Article


Testing Slim Framework actions

To test a Slim Framework action, you need a request and a response object and mock whatever is in the action. This is one way to do this. Consider this simple echo action that returns the query...

View Article

Configuration in Slim Framework

Configuration in Slim Framework is nice and simple: the App's constructor takes a configuration array for the DI container; $config = []; $app = new Slim\App($config); Setting up The settings sub-array...

View Article


Using Eloquent in Slim Framework

Eloquent is one of the easier ORMs to get started with, so let's look at how to use and test it within a Slim Framework application. Set up You can add Eloquent to your Slim project via composer:...

View Article

Overriding Slim 3's error handling

Slim 3 registers two error handers: errorHandler to trap PHP Exceptions phpErrorHandler to trap PHP 7 Errors This means that if you want to override the default error handlers, you need to override...

View Article

DI Factories for Slim controllers

When using classes for route actions in Slim 3, I recommend using a single class for each route. However you can use a single class for multiple routes. To register a class method to a route you pass a...

View Article
Browsing all 38 articles
Browse latest View live