dou8mwz5079 2014-10-17 18:49
浏览 11

能够返回自己网址的实体

I realize similar questions have been asked and answered, but bear with me because I haven't found the answers satisfactory in that, I still don't see how to solve my problem. I just understand "you shouldn't do that". Fine, but can someone help me understand how to accomplish this (seemingly) simple task?

I have a number of entities (i use that term loosely, these are not doctrine entities, they are simply from-scratch data models that load data from an external API). I would like some of these entities to have a getUrl() function, so that anywhere I encounter them, I can simply call $entity->getUrl() and have a proper and consistent url to use.

Initially I was constructing these url paths by hand, but then realized, "I should be using the urls defined in the routing configuration to generate these. Then they will REALLY be guaranteed to be consistent site-wide". So I search and come across these answers on SO that say "Your entities shouldn't know about anything but other entities" and "Create a separate service." Well, fine, but I still want an $entity->getUrl() method to call! Is it impossible to achieve this and still adhere to basic principles? Can someone explain to me how I can get it done? If I create a separate service, I still don't seem to be able to accomplish my goal, since "you shouldn't access services from inside entities."

What's a guy to do? Can anyone help me understand?

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭