How to install Doctrine Extensions in a Symfony2 project

后端 未结 3 1598
被撕碎了的回忆
被撕碎了的回忆 2020-12-09 11:01

I guess that this is really trivial and stupid question, but I don\'t know how to install Doctrine Extensions - https://github.com/beberlei/DoctrineExtensions in my Symfony2

相关标签:
3条回答
  • 2020-12-09 11:36

    There also is a nice fork by wiredmedia of @beberlei which includes even more datetime_functions like DATE() itself:

    This is an unsanctioned fork of https://github.com/beberlei/DoctrineExtensions since he seems to have gone off grid and is not merging pull requests.

    Unfortunately Version 0.1 just includes the fork and not all the functions. We are waiting for a stable release:

    Please create taged stable version for set in my composer #2

    But you can add them manually unitl a stable version is out.

    0 讨论(0)
  • 2020-12-09 11:39

    You can install it via composer. Just add it to your composer.json and then php composer.phar update beberlei/DoctrineExtensions

    "beberlei/DoctrineExtensions": "*",
    

    Then you can register functions to your ORM

    doctrine:
        orm:
          auto_generate_proxy_classes: %kernel.debug%
          entity_managers:
            default:
              auto_mapping: true
              dql:
                datetime_functions:
                  MONTH: DoctrineExtensions\Query\Mysql\Month
                  YEAR: DoctrineExtensions\Query\Mysql\Year
    
    0 讨论(0)
  • 2020-12-09 11:56

    Here is how to use DoctrineExtensions in the context of Symfony using the DoctrineBundle.

    First install the package DoctrineExtensions:

    composer require beberlei/doctrineextensions
    

    Then add to your doctrine configuration (doctrine.yaml file) the DQL functions you want to include in your application:

    doctrine:
        # Register types this way in the dbal config part
        dbal:
            types:
                carbondatetime: DoctrineExtensions\Types\CarbonDateTimeType
        # Register DQL functions in the ORM part
        orm:
            dql:
                string_functions:
                    FIND_IN_SET: DoctrineExtensions\Query\Mysql\FindInSet
                numeric_functions:
                    SIN: DoctrineExtensions\Query\Mysql\Sin
                datetime_functions:
                    DATE: DoctrineExtensions\Query\Mysql\Date
    

    This is an example, feel free to adjust to your needs (you can remove sections).

    0 讨论(0)
提交回复
热议问题