Controller Patterns in Slim 3
I would suggest that you give a quick read on http://glenneggleton.com/page/slim-3-controllers-and-actions as this article will build on some of the previous stuff there.
I would suggest that you give a quick read on http://glenneggleton.com/page/slim-3-controllers-and-actions as this article will build on some of the previous stuff there.
Recently I have been fielding a lot of questions about how to mock PSR-7 objects to unit test Slim. A lot of people have found it difficult because of the complexity of the constructors of the Slim HTTP classes. I can't say I blame them, it's something that the core team is working on improving. The HTTP classes are heavily coupled to the Environment object.
One of the main structural differences in switching from V2 to V3 of the Slim framework is the action method signature. In slim 2 it was just simple, there was nothing except the route parameters passed into the callable, whether it was a Closure or a controller. This provided a super easy API to write complex controllers.
The encoding type of your request matters. In Slim 3 we try to support a wide variety of different formats to make sure you don't have to. I want to take some time to demystify how this process works. Let's take a look.
In this article we will take a look at how we can use Slim to create an MVC pattern. Later we will learn how to modify our Controller and create different Actions.
Let's get started.
For those uninitiated Slim is an unopinionated php micro-framework. Slim lets you do things how you want, and does not force you into structures or patterns.
In this blog post we are going to cover the basics and get you up and running quickly with Slim