Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Symfony中将抽象类和接口与ORM一起使用,未找到接口 namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FoxBundle\Entity\BusinessUnit as BaseBU; use AppBundle\Model\BusinessUnitInterface; /** * @ORM\Entity * @ORM\Table(name="business_unit_fox") */ class BusinessUnitFox extends BaseBU implements BusinessUnitInterface { /** * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * {@inheritDoc} * @see \AppBundle\Model\BusinessUnitInterface::__toString() */ public function __toString() { return $this->getId(); } }_Php_Symfony_Doctrine Orm - Fatal编程技术网

Php 在Symfony中将抽象类和接口与ORM一起使用,未找到接口 namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FoxBundle\Entity\BusinessUnit as BaseBU; use AppBundle\Model\BusinessUnitInterface; /** * @ORM\Entity * @ORM\Table(name="business_unit_fox") */ class BusinessUnitFox extends BaseBU implements BusinessUnitInterface { /** * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * {@inheritDoc} * @see \AppBundle\Model\BusinessUnitInterface::__toString() */ public function __toString() { return $this->getId(); } }

Php 在Symfony中将抽象类和接口与ORM一起使用,未找到接口 namespace AppBundle\Entity; use Doctrine\ORM\Mapping as ORM; use FoxBundle\Entity\BusinessUnit as BaseBU; use AppBundle\Model\BusinessUnitInterface; /** * @ORM\Entity * @ORM\Table(name="business_unit_fox") */ class BusinessUnitFox extends BaseBU implements BusinessUnitInterface { /** * @ORM\Column(type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $id; /** * {@inheritDoc} * @see \AppBundle\Model\BusinessUnitInterface::__toString() */ public function __toString() { return $this->getId(); } },php,symfony,doctrine-orm,Php,Symfony,Doctrine Orm,我有一个项目,它使用三个不同的数据库,第一个是主数据库,我可以对第二个数据库进行更改,这两个数据库属于不同的项目,但我需要访问其中的数据。下面是一个简化的目录结构 Src 应用包 实体 BusinessUnitsFox DriverMax 车箱 模型 业务接口 UDODRIVER接口 车辆接口 狐狸精 实体 业务单位 车辆 最大束 实体 DriverMax 以下是车辆和驾驶员相似的业务单元抽象类和接口的文件 <?php // src/AppBundle/Mo

我有一个项目,它使用三个不同的数据库,第一个是主数据库,我可以对第二个数据库进行更改,这两个数据库属于不同的项目,但我需要访问其中的数据。下面是一个简化的目录结构

Src

  • 应用包

    • 实体
      • BusinessUnitsFox
      • DriverMax
      • 车箱
    • 模型
      • 业务接口
      • UDODRIVER接口
      • 车辆接口
  • 狐狸精

    • 实体
      • 业务单位
      • 车辆
  • 最大束
    • 实体
      • DriverMax
以下是车辆和驾驶员相似的业务单元抽象类和接口的文件

<?php
// src/AppBundle/Model/BusinessUnitInterface.php

namespace AppBundle\Model;

interface BusinessUnitInterface
{
    /**
     * @return string
     */
    public function __toString();
}
config.yml

# Doctrine Configuration
doctrine:
    dbal:
        default_connection: maxdb
        connections:
            maxdb:
                # ...
            foxdb:
                # ...
            max2db:
                # ...
    orm:
        resolve_target_entities:
            AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
            AppBundle\Model\UDODriver: AppBundle\Entity\DriverMax
            AppBundle\Model\BusinessUnit: AppBundle\Entity\BusinessUnitFox
        auto_generate_proxy_classes: "%kernel.debug%"
        default_entity_manager: maxem
        entity_managers:
            maxem:
                connection: maxdb
                mappings:
                    AppBundle: 
                    BWTCalendarBundle: ~
                    BWTFMBundle: ~
                    BWTHealthCheckBundle: ~
                    BWTSkytrackBundle: ~
                    BWTTelematicsBundle: ~
            foxem:
                connection: foxdb
                mappings:
                    FoxBundle: ~
            max2em:
                connection: max2db
                mappings:
                    MaxBundle: ~
当我执行SQL调用时,我得到以下错误

SQLSTATE[42S02]:找不到基表或视图:1146表“远程通信.车辆”不存在

因此,我运行了
doctrine:schema:update
,得到了以下错误

[条令\Common\Persistence\Mapping\MappingException]
类“AppBundle\Model\BusinessUnitInterface”不存在

有什么我遗漏的吗


是否可以从抽象类声明OneToMany关系?

您忘记了UDODriverInterface和BusinessUnitInterface的接口后缀。您可以按照在抽象类和接口上进行映射

resolve_target_entities:
            AppBundle\Model\VehicleInterface: AppBundle\Entity\VehicleFox
            AppBundle\Model\UDODriverInterface: AppBundle\Entity\DriverMax
            AppBundle\Model\BusinessUnitInterface: AppBundle\Entity\BusinessUnitFox

请注意,对于当前的声明,您的AppBundle\Entity\BusinessUnitFox类不是抽象的。

谢谢@OlivierC我一直在使用该链接,但肯定已经盯着它太久了,不会错过它。