Doctrine2 - 单表继承
我正在尝试应用此
我有 2 个文件。第一个是 ProjectSetting.php
namespace Rueckgrat\App\Models;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity()
* @ORM\Table(name="project_setting")
* @ORM\HasLifecycleCallbacks()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="is_production", type="integer")
* @ORM\DiscriminatorMap({"0" = "ProjectCalculation", "1" = "ProjectSetting"})
*/
class ProjectSetting
{
// More code here
}
第二个是 ProjectCalculation.php
namespace Rueckgrat\App\Models;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
*/
class ProjectCalculation extends \Rueckgrat\App\Models\ProjectSetting
{
....
}
任何帮助或提示表示赞赏。
更新:
完整错误消息: 致命错误:无法在第 17 行 /Applications/MAMP/htdocs/Rueckgrat/app/models/ProjectSetting.php 中重新声明类 Rueckgrat\App\Models\ProjectSetting
我刚刚尝试了 Doctrine 文档中的示例,只是分成两个实体文件,它不工作。然后我将 ProjectCalculation 类复制到 ProjectSetting 文件中,它正在工作。
更新 2:
我无法更新我的架构,但当我保存 ProjectCalculation 实体时,它会将正确的鉴别器保存到 project_setting 表中。
I'm trying to apply this tutorial to my project, but I don't get it working. Everytime I try to update my schema i get an error:
Fatal error: Cannot redeclare class Rueckgrat\App\Models\ProjectSetting in.....
I have 2 files. The first one is ProjectSetting.php
namespace Rueckgrat\App\Models;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity()
* @ORM\Table(name="project_setting")
* @ORM\HasLifecycleCallbacks()
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="is_production", type="integer")
* @ORM\DiscriminatorMap({"0" = "ProjectCalculation", "1" = "ProjectSetting"})
*/
class ProjectSetting
{
// More code here
}
The second one is ProjectCalculation.php
namespace Rueckgrat\App\Models;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
*/
class ProjectCalculation extends \Rueckgrat\App\Models\ProjectSetting
{
....
}
Any help or hint appreciated.
Update:
Full error message:
Fatal error: Cannot redeclare class Rueckgrat\App\Models\ProjectSetting in /Applications/MAMP/htdocs/Rueckgrat/app/models/ProjectSetting.php on line 17
I just tried the example from the Doctrine documentation, just splited in two entity files and it is not working. Then i copied the ProjectCalculation class in the file of ProjectSetting and it is working.
Update 2:
I can't update my Schema, but it is saving the correct discriminator to the project_setting table, when i save an ProjectCalculation Entity.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能是您计算机上的 PHP 加速器的问题。请关闭 APC 或 XCache(无论您有什么),重新启动 PHP/Apache,然后重试。
This can be the problem with PHP accelerator on your machine. Please turn off APC or XCache (whatever you have there), restart PHP/Apache and try again.