尝试在Slim Framework 4中使用Doctrine,但没有文档可用。按照链接http://www.slimframework.com/docs/v3/cookbook/database-doctrine.html上的信息会出现错误。
找不到“slim container”类。
<?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
);
};
dependencies.php
中使用的类的命名空间。您是复制粘贴此代码吗?这只是一个示例,可能在Doctrine中进行了更改。 - Максим ДубининMappingDriver $driverImpl
参数。 - Marcus Christiansen