If you are upgrading from version 2 to version 3, these are the significant changes that
you need to be aware of.
New PHP version
Slim 3 requires PHP 5.5+
New Route Function Signature
Getting _GET and _POST variables
Hooks
Hooks are no longer part of Slim as of v3. You should consider reimplementing any functionality associated with the default hooks in Slim v2 as middleware instead. If you need the ability to apply custom hooks at arbitrary points in your code (for example, within a route), you should consider a third-party package such as Symfony’s EventDispatcher or Zend Framework’s EventManager.
Removal HTTP Cache
In Slim v3 we have removed the HTTP-Caching into its own module Slim\Http\Cache.
Removal of Stop/Halt
Slim Core has removed Stop/Halt.
In your applications, you should transition to using the withStatus() and withBody() methods.
Changed Redirect
In Slim v2.x one would use the helper function $app->redirect(); to trigger a redirect request.
In Slim v3.x one can do the same with using the Response class like so.
Example:
Middleware Signature
The middleware signature has changed from a class to a function.
New signature:
You can still use a class:
Middleware Execution
Application middleware is executed as Last In First Executed (LIFE).
Flash Messages
Flash messages are no longer a part of the Slim v3 core but instead have been moved to seperate Slim Flash package.
Cookies
In v3.0 cookies has been removed from core. See FIG Cookies for a PSR-7 compatible cookie component.
Removal of Crypto
In v3.0 we have removed the dependency for crypto in core.
New Router
Slim now utilizes FastRoute, a new, more powerful router!
This means that the specification of route patterns has changed with named parameters now in braces and square brackets used for optional segments:
Route Middleware
The syntax for adding route middleware has changed slightly.
In v3.0:
urlFor() is now pathFor() in the router
urlFor() has been renamed pathFor() and can be found in the router object:
Also, pathFor() is base path aware.
Container and DI … Constructing
Slim uses Pimple as a Dependency Injection Container.
PSR-7 Objects
Request, Response, Uri & UploadFile are immutable.
This means that when you change one of these objects, the old instance is not updated.