dqmq0654 2012-07-25 14:00
浏览 42
已采纳

我该如何对待注释?

I use custom MVC framework. I want to use annotations above action to display title in view like:

class controller {
    /**
    * @title = some title
    */
    public function action(){
    }
}

To do this I use ReflectionMethod::getDocComment and then parse comment using simple Regex, make title as global variable and use it in my view. Of course, this is a solution but really bad one because in future I may need to use annotations not just for defining titles (for example, to define rules in models. Like Symphony does).

My problem is that I have no idea where to save metadata.

  • 写回答

1条回答 默认 最新

  • doudao1282 2012-07-25 14:13
    关注

    I don't think its a great idea to store front end/public information in a docblock comment, its very unwieldy as you're discovering and not very intuitive for other developers who come along after you. Comments should be kept for documentation and meta information about the internal workings of the system.

    To store information like that you should either use a database, some kind of class variable or an external configuration/language file. An even better alternative is some kind of templating library to handle things like page titles & view loading, which you can then call from the controller method and define the information there.

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

报告相同问题?

悬赏问题

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