๐ Quick Start
Lets start building our application using Symfony and MongoDB Doctrine ODM.
Build a skeleton projectโ
We will start building a project called rentals.
composer create-project symfony/skeleton rentals
Install MongoDB Extensionโ
- Mac
- Linux
- Windows
cd rentals
pecl install mongodb
Verify the php.ini
file to point to the installed mongodb.so
.
cd rentals
sudo apt-get install php-pear
sudo pecl install mongodb
Verify the php.ini
file to point to the installed mongodb.so
.
With Windows, users will need to fetch the DLL, as mentioned here and add it to their PHP installation.
Verify the php.ini
file to point to the installed mongodb.dll
Install driversโ
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.
Configure the MongoDB ODMโ
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
Install other dependenciesโ
Formโ
composer require symfony/form
twig bundleโ
composer require symfony/twig-bundle
Assetsโ
composer require symfony/asset
By the end of this page you will haveโ
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.