Skip to content
  • About
    • What is Symfony?
    • Community
    • News
    • Contributing
    • Support
  • Documentation
    • Symfony Docs
    • Symfony Book
    • Screencasts
    • Symfony Bundles
    • Symfony Cloud
    • Training
  • Services
    • Platform.sh for Symfony Best platform to deploy Symfony apps
    • SymfonyInsight Automatic quality checks for your apps
    • Symfony Certification Prove your knowledge and boost your career
    • SensioLabs Professional services to help you with Symfony
    • Blackfire Profile and monitor performance of your apps
  • Other
  • Blog
  • Download
sponsored by
  1. Home
  2. Documentation
  3. Bundles
  4. StofDoctrineExtensionsBundle
  5. Configuration

Configuration

Edit this page

Add the extensions to your mapping

Some of the extensions use their own entities to do their work. You need to register their mapping in Doctrine when you want to use them.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# app/config/config.yml
# (or config/packages/doctrine.yaml if you use Flex)
doctrine:
    orm:
        entity_managers:
            default:
                mappings:
                    gedmo_translatable:
                        type: annotation
                        prefix: Gedmo\Translatable\Entity
                        dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translatable/Entity"
                        alias: GedmoTranslatable # (optional) it will default to the name set for the mapping
                        is_bundle: false
                    gedmo_translator:
                        type: annotation
                        prefix: Gedmo\Translator\Entity
                        dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Translator/Entity"
                        alias: GedmoTranslator # (optional) it will default to the name set for the mapping
                        is_bundle: false
                    gedmo_loggable:
                        type: annotation
                        prefix: Gedmo\Loggable\Entity
                        dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Loggable/Entity"
                        alias: GedmoLoggable # (optional) it will default to the name set for the mapping
                        is_bundle: false
                    gedmo_tree:
                        type: annotation
                        prefix: Gedmo\Tree\Entity
                        dir: "%kernel.project_dir%/vendor/gedmo/doctrine-extensions/src/Tree/Entity"
                        alias: GedmoTree # (optional) it will default to the name set for the mapping
                        is_bundle: false

Note

If you are using the short syntax for the ORM configuration, the mappings key is directly under orm:

Note

If you are using several entity managers, take care to register the entities for the right ones.

Note

The mapping for MongoDB is similar. The ODM documents are in the Document subnamespace of each extension instead of Entity.

Note

If you added any of these mappings, be sure to update your schema to add the new table(s) - i.e. by generating and executing a migration.

Configure the entity managers

You have to activate the extensions for each entity manager for which you want to enable the extensions. The id is the id of the DBAL connection when using the ORM behaviors. It is the id of the document manager when using mongoDB.

This bundle needs a default locale used if the translation does not exists in the asked language. If you don't provide it explicitly, it will default to en.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# app/config/config.yml
# (or config/packages/stof_doctrine_extensions.yaml if you use Flex)
stof_doctrine_extensions:
    default_locale: en_US

    # Only used if you activated the Uploadable extension
    uploadable:
        # Default file path: This is one of the three ways you can configure the path for the Uploadable extension
        default_file_path:       "%kernel.project_dir%/public/uploads"

        # Mime type guesser class: Optional. By default, we provide an adapter for the one present in the Mime component of Symfony
        mime_type_guesser_class: Stof\DoctrineExtensionsBundle\Uploadable\MimeTypeGuesserAdapter

        # Default file info class implementing FileInfoInterface: Optional. By default we provide a class which is prepared to receive an UploadedFile instance.
        default_file_info_class: Stof\DoctrineExtensionsBundle\Uploadable\UploadedFileInfo
    orm:
        default: ~
    mongodb:
        default: ~
1
2
3
4
5
6
7
8
9
10
11
12
<!-- app/config/config.xml -->
<!-- (or config/packages/stof_doctrine_extensions.yaml if you use Flex) -->
<container xmlns:stof-doctrine-extensions="http://example.org/schema/dic/stof_doctrine_extensions">
    <stof-doctrine-extensions:config default-locale="en_US">
        <stof-doctrine-extensions:orm>
            <stof-doctrine-extensions:entity-manager id="default" />
        </stof-doctrine-extensions:orm>
        <stof-doctrine-extensions:mongodb>
            <stof-doctrine-extensions:document-manager id="default" />
        </stof-doctrine-extensions:mongodb>
    </stof-doctrine-extensions:config>
</container>

Activate the extensions you want

By default the bundle does not attach any listener. For each of your entity manager, declare the extensions you want to enable:

1
2
3
4
5
6
7
8
9
10
# app/config/config.yml
# (or config/packages/stof_doctrine_extensions.yaml if you use Flex)
stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: true
            timestampable: false # not needed: listeners are not enabled by default
        other:
            timestampable: true
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<!-- app/config/config.xml -->
<!-- (or config/packages/stof_doctrine_extensions.yaml if you use Flex) -->
<container xmlns:stof-doctrine_extensions="http://example.org/schema/dic/stof_doctrine_extensions">
    <stof-doctrine-extensions:config default-locale="en_US">
        <stof-doctrine-extensions:orm>
            <stof-doctrine-extensions:entity-manager
                id="default"
                tree="true"
                timestampable="false"
            />
            <stof-doctrine-extensions:entity-manager
                id="other"
                timestampable="true"
            />
        </stof-doctrine-extensions:orm>
    </stof-doctrine-extensions:config>
</container>

Same is available for MongoDB using document-manager in the XML files instead of entity-manager.

Caution

If you configure the listeners of an entity manager in several configuration files, the last one will be used. So you have to list all the listeners you want to detach.

Use the DoctrineExtensions library

All explanations about this library are available on the official DoctrineExtensions documentation.

This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.
TOC
    Version
    Check Code Performance in Dev, Test, Staging & Production

    Check Code Performance in Dev, Test, Staging & Production

    Become certified from home

    Become certified from home

    Version:

    Table of Contents

    • Add the extensions to your mapping
    • Configure the entity managers
    • Activate the extensions you want
    • Use the DoctrineExtensions library

    Symfony footer

    Avatar of adursun, a Symfony contributor

    Thanks adursun for being a Symfony contributor

    2 commits • 4 lines changed

    View all contributors that help us make Symfony

    Become a Symfony contributor

    Be an active part of the community and contribute ideas, code and bug fixes. Both experts and newcomers are welcome.

    Learn how to contribute

    Symfony™ is a trademark of Symfony SAS. All rights reserved.

    • What is Symfony?

      • What is Symfony?
      • Symfony at a Glance
      • Symfony Components
      • Symfony Releases
      • Security Policy
      • Logo & Screenshots
      • Trademark & Licenses
      • symfony1 Legacy
    • Learn Symfony

      • Symfony Docs
      • Symfony Book
      • Reference
      • Bundles
      • Best Practices
      • Training
      • eLearning Platform
      • Certification
    • Screencasts

      • Learn Symfony
      • Learn PHP
      • Learn JavaScript
      • Learn Drupal
      • Learn RESTful APIs
    • Community

      • Symfony Community
      • SymfonyConnect
      • Events & Meetups
      • Projects using Symfony
      • Contributors
      • Symfony Jobs
      • Backers
      • Code of Conduct
      • Downloads Stats
      • Support
    • Blog

      • All Blog Posts
      • A Week of Symfony
      • Case Studies
      • Cloud
      • Community
      • Conferences
      • Diversity
      • Living on the edge
      • Releases
      • Security Advisories
      • Symfony Insight
      • Twig
      • SensioLabs Blog
    • Services

      • SensioLabs services
      • Train developers
      • Manage your project quality
      • Improve your project performance
      • Host Symfony projects

      Powered by

    Follow Symfony