我正在创建一个捆绑包,旨在从二级数据库中提取数据。我不知道我还能添加或更改什么配置来使其工作。我也试过直接将连接传入仓库。理想情况下,使用 bundle 的工具只需将存储库作为参数传入,就能轻松使用它。
The class 'SRC\SRC\DataBundle\Entity\Course' was not found in the chain configured namespaces
doctrine.yml
在导入bundle的工具中,SECONDARY_DATA是一个文件。SECONDARY_DATA是我试图连接实体管理器的文件。
doctrine:
dbal:
default_connection: default
connections:
default:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(DATABASE_URL)%'
SECONDARY_DATA_CONN:
# configure these for your database server
driver: 'pdo_mysql'
server_version: '5.6'
charset: utf8mb4
default_table_options:
charset: utf8mb4
collate: utf8mb4_unicode_ci
url: '%env(SECONDARY_DATABASE_URL)%'
orm:
auto_generate_proxy_classes: '%kernel.debug%'
default_entity_manager: default
entity_managers:
default:
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
connection: default
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
SECONDARY_DATA:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: SECONDARY_DATA_CONN
auto_mapping: false
services.yml
文件的主工具。为了保护隐私,我改变了一些路径和名称。
SRC\SRC\DataBundle\Entity\Repository\CourseRepository:
alias: 'src.src.data_bundle.course.repository'
services.yml
文件的名称。
services:
src.src.data_bundle.course.repository:
class: SRC\SRC\DataBundle\Entity\Repository\CourseRepository
factory: ['@doctrine.orm.SECONDARY_DATA_entity_manager', getRepository] # where i believe the entity manager will know to use the correct database
public: false
arguments:
- 'SRC\SRC\DataBundle\Entity\Course'
储存库文件
namespace SRC\SRC\DataBundle\Entity\Repository;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
class CourseRepository extends ServiceEntityRepository
{}
这就是我最后使用ORM条目上的映射来解决它的方法。
SECONDARY_data:
naming_strategy: doctrine.orm.naming_strategy.underscore
connection: SECONDRARY_data_CONN
auto_mapping: false
mappings:
DataBundle:
type: annotation
prefix: UCI\AWT\DataBundle\Entity
dir: "%kernel.project_dir%/.../.../data-bundle/Entity"
is_bundle: false