2017-09-09 11 views
1

Pleague v2.4をSlim v3.8.1とするにはどうすればよいですか?Slim 3 + Pleague 2.4 - エイリアス(ルータ)はコンテナによって管理されていませんか?

このexampleに続いて、私が試した:

// PSR 7 standard. 
use Slim\Http\Request; 
use Slim\Http\Response; 

// Import classes. 
use Slim\App as Slim; 

use League\Container\Container; 
$container = new Container; 

// Required to enable auto wiring. 
$container->delegate(
    new \League\Container\ReflectionContainer 
); 

// Get an instance of Slim. 
$app = new Slim($container); 

は私が取得:

Fatal error: Uncaught League\Container\Exception\NotFoundException: Alias (router) is not being managed by the container in /var/www/html/projectA/vendor/league/container/src/Container.php:266 Stack trace: #0 /var/www/html/projectA/vendor/league/container/src/Container.php(93): League\Container\Container->getFromDelegate('router', Array) #1 /var/www/html/projectA/vendor/slim/slim/Slim/App.php(239): League\Container\Container->get('router') #2 /var/www/html/projectA/vendor/slim/slim/Slim/App.php(143): Slim\App->map(Array, '/', Object(Closure)) #3 /var/www/html/projectA/public/index.php(53): Slim\App->get('/', Object(Closure)) #4 {main} thrown in /var/www/html/projectA/vendor/league/container/src/Container.php on line 266

任意のアイデア?

答えて

1

Slimが、追加したコンテナに定義されていないrouterにアクセスしようとしています。スリムでは\Slim\DefaultServicesProviderで追加されます。 DIコンテナが配列アクセスをサポートしていないため、使用できません。

この問題を解決するためのオプションは、デリゲートとしてスリムコンテナを設定することで、その後、League\Container\Containerスリムコンテナを介してルータや他のすべてのものを取得します:助けを

$container = new \League\Container\Container; 
$container->delegate(new \Slim\Container()); 
$app = new \Slim\App($container); 
+0

感謝を! – laukok

関連する問題