doujiaci7976 2013-08-28 14:49
浏览 12

MVC:视图中的动态操作链接:放置业务逻辑的位置(zend2)

So, I am fairly new to Zend 2 and MVC as a whole, and I find myself in a situation where I want to follow best practices to make my code reusable and easy to understand.

The particular scenario I want to deal with is the following. Let's say I am writing an editorial application, where users can send articles, but they need to be approved before they are published. When you access an article /article/view/101 , you get a page with the article info on one side (Status, Author, Date, Title, Body) and on the sidebar you get a set of actions.

The set of actions (links) changes based on the type of user viewing the article (guest, user, reviewer or admin) and also based on the status of the article (draft,finished,published)

So the question is: Where do on the MVC model do I put the business logic to decide which actions (links) to put on the sidebar?

  • The controller does not seem appropriate because I would be adding Business Logic there, and also adding HTML (bad + bad)
  • The view does not work either because I would be adding business logic.
  • A service doesn't seem to work either because it seems I would be either adding HTML, or calling partials from there, and that should not be done either...

The only thing I could think of is doing the Business Logic in a service or helper (since more than one model is needed, article and user) and return an 'array' of actions (no HTML). Then the view processes those to actually get the HTML, but I'm not sure if that is the way to do it, and wanted some experienced input.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 opencv图像处理,需要四个处理结果图
    • ¥15 无线移动边缘计算系统中的系统模型
    • ¥15 深度学习中的画图问题
    • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
    • ¥15 Python报错怎么解决
    • ¥15 simulink如何调用DLL文件
    • ¥15 关于用pyqt6的项目开发该怎么把前段后端和业务层分离
    • ¥30 线性代数的问题,我真的忘了线代的知识了
    • ¥15 有谁能够把华为matebook e 高通骁龙850刷成安卓系统,或者安装安卓系统
    • ¥188 需要修改一个工具,懂得汇编的人来。