Your code is apparently based on Slim 3 documentation at http://www.slimframework.com/docs/objects/router.html , which does not contain all the necessary code to throw an exception thrown.
Basically you have two options to make it work.
Option 1:
Import the namespace into index.php , as is done for Request and Response :
use \Interop\Container\ContainerInterface as ContainerInterface;
Option 2:
Change the constructor of TopPageController to:
public function __construct(Interop\Container\ContainerInterface $ci) { $this->ci = $ci; }
TL DR
The reason the exception is thrown is because the Slim\Container class uses the Interop\Container\ContainerInterface interface (see source code):
use Interop\Container\ContainerInterface;
Since Slim\Container extends Pimple\Container , everything should be a valid (working) type declaration for your controller method:
public function __construct(Pimple\Container $ci) { $this->ci = $ci; }
... or even...
public function __construct(ArrayAccess $ci) { $this->ci = $ci; }
source share