Symfony accesses MongoDB through DoctrineMongoDBODM

Source: Internet
Author: User
Symfony accesses MongoDB through DoctrineMongoDBODM. Development Environment: PHP5.3.0 + Symfony1.4.4DoctrineMongoDBODM1.0.0MongoDB1.4.4

Symfony accesses MongoDB through DoctrineMongoDBODM. Development Environment: PHP 5.3.0 +/Symfony 1.4.4/DoctrineMongoDBODM 1.0.0/MongoDB 1.4.4

I. Overview

Development Environment: PHP 5.3.0 +/Symfony 1.4.4/DoctrineMongoDBODM 1.0.0/MongoDB 1.4.4

Tip: This article requires you to understand the following content: PHP namespace, Symfony framework, MongoDB, and Doctrine ODM (download ODM)
For details about how to install and use apsaradb for MongoDB on the Win platform, see: Operating apsaradb for MongoDB in PHP.

Ii. Configuration and development steps
1. Create a Symfony project in the command line. Assume that the main directory is ROOT and the project name is MG.
> Cd ROOT
> Php lib/vendor/symfony/data/bin/symfony generate: project MG -- orm = none

2. Extract the downloaded Doctrine ODM to the ROOT/lib/vendor/doctrine/lib directory. For example, ROOT/lib/vendor/doctrine/lib/Doctrine/ODM.

3. Create documents under ROOT/lib to store the dataset model, similar to the table model, and create two Proxy directories: generate and proxies (ROOT/lib/generate/proxies)

4. Modify the project configuration file ROOT/config/ProjectConfiguration. class. php. The Code is as follows:

5. Run the Symfony command on the command line to create the frontend and mg modules of the application.

> Php symfony generate: app frontend

> Php symfony generate: module frontend mg

6. Create three files in the ROOT/lib/actions documents Directory: MongoDB operation class (actions. class. php). The user dataset is similar to the user table model (Users. class. php), the blog article dataset is similar to the blog article table model (BlogPost. class. php), the content is as follows:

7. Modify the action class of the module mg (ROOT/apps/frontend/modules/mg/actions. class. php)

So far, the simple example of Symfony operations on MongoDB has been completed. Start MongoDB and the Web server and enter it in the browser to see the effect. For more information, see the following link.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.