我应该有一个新的控制器还是相同的控制器来实现这个?
例如,我有一个广告商控制器,现在,我需要广告商拥有广告。所以,我的问题是,我该把它放在哪里?我应该有一个新的广告控制器还是在广告商控制器中进行?请建议。谢谢。
For example, I have an advertiser controller, now, I need the advertiser have the advertisement. So, my question is, where do I put this? Should I have a new advertisement controller or do it in the advertiser controller? Please suggest. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
嗯,我认为这实际上取决于您的用户如何与网站交互以及广告在整个领域中的含义。
根据您所说的,我可能会创建一个具有
Create
方法的AdvertisementController
。我假设您会根据身份验证知道用户/广告商 ID,因此您可以为GET
使用一个空的Create
方法签名(用于显示表单),并且Create
方法签名,该方法签名采用Advertisement
对象作为POST
。我不知道您正在使用的语言和/或您正在使用的 MVC 框架,但希望这会有所帮助。所以我希望这会有所帮助,或者至少给你一些关于如何设计这个的想法。我会选择单独的控制器。从组织上来说,至少,它将使您的广告逻辑得到很好的控制(而不是潜在的臃肿的广告商控制器)。
祝你好运!
Well, I think it really depends on how your users will interact with the site and what an advertisement means in the overall domain.
Just based on what you've said, I would probably create an
AdvertisementController
that has aCreate
method. I'm assuming you'll know the user/advertiser id based on authentication, so you can have an emptyCreate
method signature for theGET
(to display the form) and aCreate
method signature that takes anAdvertisement
object for thePOST
. I don't know the language that you're working with and/or the MVC framework you're using, but hopefully this helps.So I hope this helps, or at least gives you some thoughts around how to design this. I'd go for the separate controller. Organizationally, at a minimum, it will keep your logic around Advertisements pretty well contained (instead of a potentially bloated Advertiser controller).
Good luck!
对我来说这是一个概念性问题。
如果广告在概念上和逻辑上由广告商“拥有” - 这就是您的答案(使用广告商控制器);另一方面,如果广告本身就是一个独立的概念(并且不完全依赖于广告商),那么这将推动您的答案(给他们自己的答案)。
测试这一点的方法是查看您可能必须实现的不同场景(根据 4 +1 架构视图模型)并让这些帮助找出答案。
To me this is a conceptual question.
If advertisements were conceptually and logically "owned" by an advertiser - that would be your answer (use the Advertiser Controller); on the other-hand, if advertisements are a stand-alone concept in their own right (and don't depend exclusively on advertisers) then that would drive your answer (give them their own one).
The way to test this is to look at the different scenarios your likely to have to implement (as per the 4+1 architectural view model) and let those help drive out the answer.