douchun1859 2017-11-23 17:40
浏览 54

如何在Zend Framework 3中自动加载继承的doctrine实体?

<?php
namespace MyProject\Model;

/**
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="discr", type="string")
 * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
 */
class Person
{
    // ...
}

/**
 * @Entity
 */
class Employee extends Person
{
    // ...
}

How to define Autoload for above doctrine entity inheritance ? Or can we put each entity in separate file such as Entity\Person.php , Employee\Person.php ?

  • 写回答

1条回答 默认 最新

  • dongmei9961 2017-11-24 09:29
    关注

    You should put every PHP class in its own file, if you want your project to be compatible with (for example) PSR-4 (Autoloader).

    Citing from the PSR-4 specification:

    1. When loading a file that corresponds to a fully qualified class name …

      1. A contiguous series of one or more leading namespace and sub-namespace names, not including the leading namespace separator, in the fully qualified class name (a “namespace prefix”) corresponds to at least one “base directory”.
      2. The contiguous sub-namespace names after the “namespace prefix” correspond to a subdirectory within a “base directory”, in which the namespace separators represent directory separators. The subdirectory name MUST match the case of the sub-namespace names.
      3. The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.

    So, if you create a class Person in MyProject\Model namespace, the autoloader will find it only in a …/Model/Person.php file. And an Employee class must go to a separate …/Model/Employee.php file in order to be available to the autoloader.

    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示