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.