将slim php连接到mongodb原则
我正在使用这个细长的php框架作为mvc结构。它也有理论联系 我想连接到我的mongodb服务器,这是doctrine mongodb包 我已经安装并设置了我的将slim php连接到mongodb原则,php,mongodb,doctrine-orm,slim,php-mongodb,Php,Mongodb,Doctrine Orm,Slim,Php Mongodb,我正在使用这个细长的php框架作为mvc结构。它也有理论联系 我想连接到我的mongodb服务器,这是doctrine mongodb包 我已经安装并设置了我的bootstrap.php,就像文档在设置步骤中所说的那样 我的slim框架中的设置文件如下所示 <?php declare(strict_types=1); use DI\ContainerBuilder; use Monolog\Logger; return function (ContainerBuilder $conta
bootstrap.php
,就像文档在设置步骤中所说的那样
我的slim框架中的设置文件如下所示
<?php
declare(strict_types=1);
use DI\ContainerBuilder;
use Monolog\Logger;
return function (ContainerBuilder $containerBuilder) {
$rootPath = realpath(__DIR__ . '/..');
// Global Settings Object
$containerBuilder->addDefinitions([
'settings' => [
// Base path
'base_path' => '',
// Is debug mode
'debug' => (getenv('APPLICATION_ENV') != 'production'),
// 'Temprorary directory
'temporary_path' => $rootPath . '/var/tmp',
// Route cache
'route_cache' =>$rootPath . '/var/cache/routes',
// View settings
'view' => [
'template_path' =>$rootPath . '/tmpl',
'twig' => [
'cache' =>$rootPath . '/var/cache/twig',
'debug' => (getenv('APPLICATION_ENV') != 'production'),
'auto_reload' => true,
],
],
// doctrine settings
'doctrine' => [
'meta' => [
'entity_path' => [ $rootPath . '/src/Entity' ],
'auto_generate_proxies' => true,
'proxy_dir' => $rootPath . '/var/cache/proxies',
'cache' => null,
],
'connection' => [
'driver' => 'pdo_sqlite',
'path' => $rootPath . '/var/blog.sqlite'
]
],
// monolog settings
'logger' => [
'name' => 'app',
'path' => getenv('docker') ? 'php://stdout' : $rootPath . '/var/log/app.log',
'level' => (getenv('APPLICATION_ENV') != 'production') ? Logger::DEBUG : Logger::INFO,
]
],
]);
if (getenv('APPLICATION_ENV') == 'production') { // Should be set to true in production
$containerBuilder->enableCompilation($rootPath . '/var/cache');
}
};
确保ext mongodb
处于暂停状态
extension=mongodb
安装Doctrine MongoDB ODM库:
composer require doctrine/mongodb-odm
为DocumentManager::class
添加DI容器定义: