我应该有一个新的控制器还是相同的控制器来实现这个?

发布于 2024-12-02 17:02:58 字数 86 浏览 1 评论 0原文

例如,我有一个广告商控制器,现在,我需要广告商拥有广告。所以,我的问题是,我该把它放在哪里?我应该有一个新的广告控制器还是在广告商控制器中进行?请建议。谢谢。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

锦欢 2024-12-09 17:02:58

嗯,我认为这实际上取决于您的用户如何与网站交互以及广告在整个领域中的含义。

根据您所说的,我可能会创建一个具有 Create 方法的 AdvertisementController 。我假设您会根据身份验证知道用户/广告商 ID,因此您可以为 GET 使用一个空的 Create 方法签名(用于显示表单),并且Create 方法签名,该方法签名采用 Advertisement 对象作为 POST。我不知道您正在使用的语言和/或您正在使用的 MVC 框架,但希望这会有所帮助。

public AdvertisementController : Controller {

  //http://server/ad/create (with optional querystring params??)
  [HttpGet]
  public ActionResult Create(){
    //get your model or modelview
    return View(model);  //return View for your Create Advertisement view
  }

  //http://server/ad/create (with post request body)
  [HttpPost]
  public ActionResult Create(Advertisment ad){
    //send your ad to the repository

    //redirect to some read page, or list, or something else
    return Redirect("Home", "Index");
  }
}

所以我希望这会有所帮助,或者至少给你一些关于如何设计这个的想法。我会选择单独的控制器。从组织上来说,至少,它将使您的广告逻辑得到很好的控制(而不是潜在的臃肿的广告商控制器)。

祝你好运!

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 a Create method. I'm assuming you'll know the user/advertiser id based on authentication, so you can have an empty Create method signature for the GET (to display the form) and a Create method signature that takes an Advertisement object for the POST. I don't know the language that you're working with and/or the MVC framework you're using, but hopefully this helps.

public AdvertisementController : Controller {

  //http://server/ad/create (with optional querystring params??)
  [HttpGet]
  public ActionResult Create(){
    //get your model or modelview
    return View(model);  //return View for your Create Advertisement view
  }

  //http://server/ad/create (with post request body)
  [HttpPost]
  public ActionResult Create(Advertisment ad){
    //send your ad to the repository

    //redirect to some read page, or list, or something else
    return Redirect("Home", "Index");
  }
}

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!

梦里寻她 2024-12-09 17:02:58

对我来说这是一个概念性问题。

如果广告在概念上和逻辑上由广告商“拥有” - 这就是您的答案(使用广告商控制器);另一方面,如果广告本身就是一个独立的概念(并且不完全依赖于广告商),那么这将推动您的答案(给他们自己的答案)。

测试这一点的方法是查看您可能必须实现的不同场景(根据 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文