所以,我第一次尝试设置php,但是我在构建器上遇到了一些麻烦。我不断地发现错误:
Uncaught exception 'DI\NotFoundException' with message 'No entry or class found for 'IConnection'' in /path/PHPDiContainer.php'我的容器设置哪里出错了?
<?php
require_once 'vendor/autoload.php';
use repositories\Connection;
use irepositories\IConnection;
use DI\ContainerBuilder;
$container = DI\ContainerBuilder::buildDevContainer();
$builder = new DI\containerBuilder();
$builder->addDefinitions([
IConnection::class => DI\object(Connection::class)
]);
$container = $builder->build();
$connection = $container->get('Connection');
... Code to show it works.
?>发布于 2016-10-20 06:35:40
IConnection::class返回完全限定的类名:irepositories\IConnection。因此,您将在PHP中以该名称注册连接。
如果您想得到它,Connection将不匹配任何东西。你得做:
$connection = $container->get('irepositories\IConnection');
// or
$connection = $container->get(IConnection::class);https://stackoverflow.com/questions/40143425
复制相似问题