Symfony : What is the meaning of auto_mapping and auto_generate_proxy_classes

前端 未结 1 1661
太阳男子
太阳男子 2021-01-17 09:00

The configuration uses :

doctrine:
dbal:
  driver:   \"%database_driver%\"
   ....
orm:
    auto_generate_proxy_classes: \"%kernel.debug%\"
    auto_mapping:         


        
相关标签:
1条回答
  • 2021-01-17 09:21

    auto_mapping is where doctrine will automatically load the mapping from your bundle Resources/config/doctrine directory.

    Setting it to false will mean that you will need to load the mappings yourself. It can be handy if you have mappings for entities rather than mapped superclasses in a vendor bundle that you want to override.

    You can do this either by way of stating the mappings in the doctrine config ...

    doctrine:
        orm:
            entity_managers:
                default:
                    mappings:
                        AcmeUnknownBundle:
                            mapping:              true
                            type:                 yml
                            dir:                  "Resources/config/doctrine"
                            alias:                ~
                            prefix:               Acme\UnknownBundle\Entity
                            is_bundle:            true
    

    adding them in some sort of mappings pass ...

    class AcmeUnknownBundle extends Bundle
    {
        public function build(ContainerBuilder $container)
        {
            parent::build($container);
            // ...
    
            $modelDir = realpath(__DIR__.'/Resources/config/doctrine/model');
            $mappings = array(
                $modelDir => 'Acme\UnknownBundle\Model',
            );
    
            $ormCompilerClass = 'Doctrine\Bundle\DoctrineBundle\DependencyInjection\Compiler\DoctrineOrmMappingsPass';
            if (class_exists($ormCompilerClass)) {
                $container->addCompilerPass(
                    DoctrineOrmMappingsPass::createYamlMappingDriver(
                        $mappings,
                        array('acme_unknown.model_manager_name'),
                        true
                ));
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题