0

I am using a PHP framework (transitioning from Zend Framework to Zend Expressive), and I have something like the following:

I have a product that has various models and customizations, and depending on those, different things are to be displayed. Below is for sample only:

  • For models X, Y, Z, variable V54 is to be shown, with a specific description
  • For models A, B, C, variable V54 is to be shown, but description is different

--

  • For models X, Y, Z, value V54 is to be shown to 2 decimal places
  • For models A, B, C, value V54 is to be shown to 3 decimal places

--

  • For models X, Y, Z, variable V56 is to be shown only for 2-rotor products, and value to be reduced by 0.1
  • For models A, B, C, variable V56 is to be shown for 2-rotor products, as is

--

  • For models X, Y, Z, variable V58 is not shown
  • For models A, B, C, variable V58 is shown

etc.

Do those rules go into the view, where I can use if/then/else statements, or do I try to compress them into the model/other layer?

How do I deal with something like this?

Dennis
  • 7,907
  • 11
  • 65
  • 115
  • view is just for display. use a service like modeltuningservice class? – Leszek P Mar 20 '18 at 14:50
  • I've added a case for variable `V58`.. how would you deal with variable that is to be shown at some times but not others? what would the modeltuningservice do..? – Dennis Mar 20 '18 at 14:52
  • How many different models of a product are there? The reason I am asking is if there aren't too many (subjective) then you could a load a different view for each model and it would handle displaying itself. `return view("product/{$model}.phtml")`.The views would extend a base view and only override the necessary properties. – waterloomatt Mar 20 '18 at 15:34
  • No. But what you describe sounds more like presentation logic. Maybe this helps a little: https://stackoverflow.com/a/16596704/727208 – tereško Mar 20 '18 at 16:45
  • @waterloomatt, there are 13 products, and each can have 1 rotor or 2, and each can theoretically have other customizations that add/subtract quantities from values to be shown – Dennis Mar 20 '18 at 19:21
  • I'd use variables in model and read them in view. It's good to split view in partials like @waterloomatt mentioned. – Mehmet SÖĞÜNMEZ Mar 22 '18 at 09:01

0 Answers0