我在将mongodb与Symfony 3.1.2集成时遇到了一些问题。我使用DoctrineMongoDBBundle。
对于'持久对象到MongoDB'阶段,一切都还可以。当我添加行:
$dm = $this->get('doctrine_mongodb')->getManager();
$dm->persist($product);
$dm->flush();
我的远程数据库没有任何反应,我收到错误消息:
Attempted to load class "MongoId" from the global namespace.
Did you forget a "use" statement?
我在Mac上使用docker beta。我的docker-compose.yml:
version: '2'
services:
application_ad:
image: busybox
volumes:
- ./:/var/www/html
- ./docker/nginx/conf.d/ad.conf:/etc/nginx/conf.d/default.conf
entrypoint: "tail -f /dev/null"
php_ad:
build: ./docker/php-fpm
links:
- db
volumes_from:
- application_ad
web_ad:
build: ./docker/nginx
ports:
- "8089:80"
links:
- php_ad
volumes_from:
- application_ad
db:
image: mongo:3.2.7
volumes:
- ./mongo-data:/data/db
ports:
- "27017:27017"
php-fpm文件:
FROM php:7-fpm
MAINTAINER Me <dev@me.com>
# nginx and php-fpm user MUST be the same
RUN usermod -u 1000 www-data
# set php.ini
RUN touch /usr/local/etc/php/conf.d/php.ini
RUN { \
echo "date.timezone = Europe/Paris"; \
echo "short_open_tag = off"; \
} >> /usr/local/etc/php/conf.d/php.ini
# composer install
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
# install php extensions dependencies
RUN apt-get update && apt-get install -my mlocate wget \
zlib1g-dev openssl libcurl4-openssl-dev libssl-dev pkg-config libgdbm-dev libjpeg-dev libpng-dev libmcrypt-dev libicu-dev g++
# install php extensions
RUN docker-php-ext-install curl
RUN docker-php-ext-configure gd --with-jpeg-dir="/usr/lib/x86_64-linux-gnu"
RUN docker-php-ext-install gd
RUN docker-php-ext-install json
RUN docker-php-ext-install mcrypt
RUN docker-php-ext-install mcrypt
RUN docker-php-ext-install intl
RUN docker-php-ext-install opcache
RUN pecl install apcu && pecl install channel://pecl.php.net/apcu_bc-1.0.3
# install mongo
RUN pecl install mongodb
RUN echo "extension=mongodb.so" > /usr/local/etc/php/conf.d/mongo.ini
# configure extensions
RUN { \
echo 'zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20151012/opcache.so'; \
echo 'opcache.memory_consumption=256'; \
echo 'opcache.interned_strings_buffer=16'; \
echo 'opcache.max_accelerated_files=20000'; \
echo 'opcache.revalidate_freq=2'; \
echo 'opcache.fast_shutdown=1'; \
echo 'opcache.enable_cli=1'; \
} > /usr/local/etc/php/conf.d/docker-php-ext-opcache.ini
RUN { \
echo 'extension=apcu.so'; \
echo 'extension=apc.so'; \
echo 'apc.enabled=1'; \
echo 'apc.shm_size=256M'; \
echo 'apc.ttl=7200'; \
echo 'apc.enable_cli=1'; \
echo 'apc.gc_ttl=3600'; \
echo 'apc.entries_hint=4096'; \
echo 'apc.slam_defense=1'; \
echo 'apc.serializer=php'; \
} > /usr/local/etc/php/conf.d/docker-php-ext-apc.ini
PHPInfo():
也许是码头工人的问题?或Symfony问题。
答案 0 :(得分:2)
我正在使用PHP 7和mongodb并使用symfony和docker。我唯一的问题是我需要安装的php扩展是mongodb而不是mongo。安装mongodb扩展后,一切正常。
这是我的作曲家要求:
"require": {
"doctrine/mongodb-odm": "^1.1.0",
"doctrine/mongodb-odm-bundle": "^3.1.0",
"alcaeus/mongo-php-adapter": "^1.0.0",
"ext-mongo": "*"
}
如果在安装作曲家时仍然失败,请在作曲家需求
下面添加此行"provide": {
"ext-mongo": "1.6.13"
}
希望有所帮助