传递给app \ Controllers \ Controller :: __ construct()的参数1必须是Interop \ Container \ ContainerInterface的实例

问题描述 投票:-1回答:1

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};
        }
    }
}
php slim-3
1个回答
0
投票

Slim\Container正在直接实现Slim\Container,而不是来自Psr\Container\ContainerInterface的接口。您的构造函数也应该将typehint更改为PSR版本。

© www.soinside.com 2019 - 2024. All rights reserved.