MVC : Dynamic action links in a view: where to put the business logic (zend2)

168 Views Asked by At

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

There are 0 best solutions below