Home > Database > Mysql Tutorial > Symfony通过DoctrineMongoDBODM访问MongoDB

Symfony通过DoctrineMongoDBODM访问MongoDB

WBOY
Release: 2016-06-07 17:05:32
Original
1031 people have browsed it

Symfony通过DoctrineMongoDBODM访问MongoDB,开发环境:PHP 5.3.0+ / Symfony 1.4.4 / DoctrineMongoDBODM 1.0.0 / MongoDB 1.4.4

一、概述

开发环境:PHP 5.3.0+ / Symfony 1.4.4 / DoctrineMongoDBODM 1.0.0 / MongoDB 1.4.4

阅读提示:本文需读者了解以下内容 PHP命名空间、Symfony框架、MongoDB、Doctrine ODM(下载ODM)
Win平台MongoDB的安装与使用可参看:《PHP操作MongoDB》 

二、配置与开发步骤
1、首先在命令行下创建Symfony项目,假设主目录为:ROOT,项目名为MG
>cd ROOT
>php lib/vendor/symfony/data/bin/symfony generate:project MG --orm=none 

2、将下载的Doctrine ODM解压至ROOT/lib/vendor/doctrine/lib目录下,eg:ROOT/lib/vendor/doctrine/lib/Doctrine/ODM 

3、在ROOT/lib下创建documents存放数据集模型,类似与表模型,同时创建Proxy的两个目录,分别为:generate和proxies(ROOT/lib/generate/proxies) 

4、修改项目配置文件ROOT/config/ProjectConfiguration.class.php,代码如下:

5、在命令行下采用Symfony命令创建应用frontend和模块mg

>php symfony generate:app frontend

>php symfony generate:module frontend mg 

6、在ROOT/lib/documents目录下创建三个文件:MongoDB操作类(Documents.class.php),用户数据集类似于用户表模型(Users.class.php),博客文章数据集类似于博客文章表模型(BlogPost.class.php),,内容如下:

7、修改模块mg的action类(ROOT/apps/frontend/modules/mg/actions/actions.class.php)

至此Symfony操作MongoDB的简易示例已完成,启动MongoDB与Web服务器,在浏览器输入,即可看到效果。深入内容请待后文或参看本文的教程链接。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template