Skip to content

Latest commit

 

History

History
127 lines (96 loc) · 3.08 KB

30-quick-start.mdx

File metadata and controls

127 lines (96 loc) · 3.08 KB

import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';

🏁 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

```shell cd rentals pecl install mongodb ``` Verify the `php.ini` file to point to the installed `mongodb.so`. ```shell 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](https://www.php.net/manual/en/mongodb.setup.php) 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.