尝试将原则与 slim 框架 4 一起使用,但没有可用的文档。通过以下链接http://www.slimframework.com/docs/v3/cookbook/database-doctrine.html上的信息给出错误。
找不到类“超薄容器”
<?php
// bootstrap.php
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Cache\FilesystemCache;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AnnotationDriver;
use Doctrine\ORM\Tools\Setup;
use Slim\Container;
require_once __DIR__ . '/vendor/autoload.php';
$container = new Container(require __DIR__ . '/settings.php');
$container[EntityManager::class] = function (Container $container): EntityManager {
$config = Setup::createAnnotationMetadataConfiguration(
$container['settings']['doctrine']['metadata_dirs'],
$container['settings']['doctrine']['dev_mode']
);
$config->setMetadataDriverImpl(
new AnnotationDriver(
new AnnotationReader,
$container['settings']['doctrine']['metadata_dirs']
)
);
$config->setMetadataCacheImpl(
new FilesystemCache(
$container['settings']['doctrine']['cache_dir']
)
);
return EntityManager::create(
$container['settings']['doctrine']['connection'],
$config
);
};