我在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:
中有这样的formtype 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容器: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
任何人都可以告诉我出了什么问题?
答案 0 :(得分:1)
entity field type接受em
选项,可让您指定实体管理器
<?php
class ModerationAnnonceForm extends AbstractType
{
public function buildForm(FormBuilder $builder, array $options)
{
$builder
->add('descAnnonce')
->add('idRubrique','entity',array(
'class' => 'AcmeModerationBundle:TRubrique',
'em' => 'spoop' // Add this
'expanded'=>true,
'multiple' =>false,
));
}
// ...
}
答案 1 :(得分:1)
尝试使用没有核心文件夹名称的bandle名称时,我有这个。它在config / security.yml
中我的案例中的文件夹结构是下一个src / Dp / UserBundle /....
我改变了这一点 `提供商:
main:
entity: { class: UserBundle:User, property: username }`
对此
`提供商:
main:
entity: { class: DpUserBundle:User, property: username }`
所以复制未知实体名称的名称(UserBundle我的案例)并搜索项目中的每个条目,检查 - 它们必须带有文件夹前缀(在我的情况下是Dp)