Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将slim php连接到mongodb原则_Php_Mongodb_Doctrine Orm_Slim_Php Mongodb - Fatal编程技术网

将slim php连接到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

我正在使用这个细长的php框架作为mvc结构。它也有理论联系

我想连接到我的mongodb服务器,这是doctrine mongodb包

我已经安装并设置了我的
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容器定义: