donglei2288 2014-07-23 09:53
浏览 68
已采纳

如何管理实体中的常量

How would one add constants (as in the example below) to an Entity class, when there is a risk of the entity being cleared and regenerated (to clean it up) some time in the future, without having to keep in mind there are constants for this Entity.

Would you generate the entity in Acme\DemoBundle\Entity as BaseEntity and extend the Entity which would contain the constants? (A bit like the 'Propel-way')

I would also like to keep the generated class clean from changes made by developers.

For example (very abstract)

<?php

    namespace Acme\DemoBundle\Entity;

    class Transition
    {
        const TYPE_ENTER = 0;
        const TYPE_EXIT = 1;

        // Generated fields (from .yml)
        private $type; // Also generated

        // Generated getters & setters (from .yml)
    }
  • 写回答

1条回答 默认 最新

  • dsv768456 2014-07-23 09:59
    关注

    I usually add the constants to the interface that the models must implement rather than the model which may not even be used.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 有人能看一下我宿舍管理系统的报修功能该怎么改啊?链表那里总是越界
  • ¥15 cs loadimage运行不了,easyx也下了,没有用
  • ¥15 r包runway详细安装教程
  • ¥15 Html中读取Json文件中数据并制作表格
  • ¥15 谁有RH342练习环境
  • ¥15 STM32F407 DMA中断问题
  • ¥15 uniapp连接阿里云无法发布消息和订阅
  • ¥25 麦当劳点餐系统代码纠错
  • ¥15 轮班监督委员会问题。
  • ¥20 关于变压器的具体案例分析