Slim Application错误
The application could not run because of the following error:
Details
Type:TypeError
Message:Argument 1 passed to app\Controllers\Controller::__construct() must be an instance of Interop\Container\ContainerInterface, instance of Slim\Container given, called in
/opt/lampp/htdocs/project/vendor/slim/slim/Slim/CallableResolver.php on line 102
调用任何方法时都会收到此错误。其他控制器扩展了此控制器Controller.php文件看起来像这样-
<?php
namespace app\Controllers;
use Interop\Container\ContainerInterface as ContainerInterface;
abstract class Controller
{
protected $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
public function __get($property)
{
if($this->container->{$property})
{
return $this->container->{$property};
}
}
}
Slim\Container
正在直接实现Slim\Container
,而不是来自Psr\Container\ContainerInterface
的接口。您的构造函数也应该将typehint更改为PSR版本。