import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
Lets start building our application using Symfony and MongoDB Doctrine ODM.
We will start building a project called rentals.
composer create-project symfony/skeleton rentals
composer require mongodb/mongodb
composer require doctrine/mongodb-odm-bundle
Manually enable the bundle by adding the following line in the config/bundles.php
file of your project, as mentioned in the documentation.
Create a src/Document
directory for the entities defined in the next sections.
Add and edit the file config/packages/doctrine_mongodb.yaml
and add the following content:
# config/packages/doctrine_mongodb.yaml
doctrine_mongodb:
auto_generate_proxy_classes: true
auto_generate_hydrator_classes: true
connections:
default:
server: '%env(resolve:MONGODB_URL)%&appName=devrel.content.php'
options: {}
default_database: '%env(resolve:MONGODB_DB)%'
document_managers:
default:
auto_mapping: true
mappings:
App:
dir: '%kernel.project_dir%/src/Document'
mapping: true
type: attribute
prefix: 'App\Document'
is_bundle: false
alias: App
composer require symfony/form
composer require symfony/twig-bundle
composer require symfony/asset
A project structure like this:
.
├── composer.json
├── composer.lock
├── symfony.lock
├── src
│ ├── Controller
│ ├── Document
├── config
│ ├── packages
│ │ ├── doctrine_mongodb.yaml
│ │ ├── framework.yaml
│ │ ├── twig.yaml
│ │ └── routing.yaml
| ├── bundles.php
├── public
│ ├── index.php
The necessary dependencies to start building a web application using Symfony and MongoDB ODM are now installed.