我在 config.yml 中有两个数据库连接:
doctrine:
dbal:
default_connection: default
connections:
default:
host: %database_host%
port: %database_port%
dbname: %database_name%
user: %database_user%
password: %database_password%
driver: %database_driver%
charset: UTF8
spoop:
host: %database_host%
port: %database_port%
dbname: %spoop_database_name%
user: %spoop_database_user%
password: %spoop_database_password%
driver: %database_driver%
charset: UTF8
orm:
default_entity_manager: default
entity_managers:
default:
connection: default
#metadata_cache_driver: apc
#query_cache_driver: apc
#result_cache_driver: apc
mappings:
AcmeUserBundle: ~
AcmeBannieresBundle: ~
FOSUserBundle: ~
#SpoopAdminBundle: ~
spoop:
connection: spoop
#metadata_cache_driver: apc
#query_cache_driver: apc
#result_cache_driver: apc
mappings:
AcmeModerationBundle: ~
auto_generate_proxy_classes: %kernel.debug%
所以在我的 acmeModerationBundle 中,我使用 spoop 连接。我在 Acme\ModerationBundle\Form 中有这样的表单类型:
class ModerationAnnonceForm extends AbstractType{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('descAnnonce')
->add('idRubrique','entity',array(
'class' => 'AcmeModerationBundle:TRubrique',
'expanded'=>true,
'multiple' =>false,
));
}
public function getDefaultOptions(array $options)
{
return array(
'data_class' => 'Acme\ModerationBundle\Entity\TAnnonces',
);
}
public function getName()
{
return 'acme_moderationbundle_annonceform';
}
}
AcmeModerationBundle:TRubrique 定义在适当的位置:Acme/Moderationbundle/Entity/TRubrique。当我尝试生成此表单时,我总是得到这个:未知实体命名空间别名'AcmeModerationBundle'。我看了一下日志,
at ORMException ::unknownEntityNamespace ('AcmeModerationBundle')
in D:\workspace\symfony_bannieres\vendor\doctrine\lib\Doctrine\ORM\Configuration.php at line 174 -+
at Configuration ->getEntityNamespace ('AcmeModerationBundle')
in D:\workspace\symfony_bannieres\vendor\doctrine\lib\Doctrine\ORM\Mapping\ClassMetadataFactory.php at line 156 -+
at ClassMetadataFactory ->getMetadataFor ('AcmeModerationBundle:TRubrique')
in D:\workspace\symfony_bannieres\vendor\doctrine\lib\Doctrine\ORM\EntityManager.php at line 257 -+
at EntityManager ->getClassMetadata ('AcmeModerationBundle:TRubrique')
in D:\workspace\symfony_bannieres\vendor\symfony\src\Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList.php at line 113 -+
at EntityChoiceList ->__construct (object(EntityManager), 'AcmeModerationBundle:TRubrique', null, null, null)
in D:\workspace\symfony_bannieres\vendor\symfony\src\Symfony\Bridge\Doctrine\Form\Type\EntityType.php at line 62 -+
at EntityType ->getDefaultOptions (array('class' => 'AcmeModerationBundle:TRubrique', 'expanded' => true, 'multiple' => false, 'data' => null))
in D:\workspace\symfony_bannieres\vendor\symfony\src\Symfony\Component\Form\FormFactory.php at line 234 -
我想它使用默认的实体管理器,我检查了 php app/console container:debug
doctrine.orm.default_entity_manager container Doctrine\ORM\EntityManager
doctrine.orm.entity_manager n/a alias for doctrine.orm.default_entity_manager
doctrine.orm.spoop_entity_manager container Doctrine\ORM\EntityManager
任何人都可以告诉我有什么问题吗?