Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy have a separate add and edit view when differences between the two are minor?
    primarykey
    data
    text
    <p>I'm wondering this after going through the Zend Framework2 tutorial but it probably applies to MVC logic in general ...</p> <p>In the tutorial, the examples walk you through having an add view (<code>module/Album/view/album/album/add.phtml</code>) and then has you create an edit template (<code>module/Album/view/album/album/edit.phtml</code>) in which much of the code is duplicated. The edit script basically has some extra logic to check for a supplied id but presents the user with the same form.</p> <p>Now, in similar cases where I haven't entirely used the MVC conventions, I would have a script that would handle both adding and editing options; the logic would assume an 'editing' action if an id was supplied and attempt to retrieve a database record for that id to populate the form fields, plus return an error if an invalid id was supplied.</p> <p>It seem that a textbook approach to MVC doesn't really encapsulate DRY principles very well if this approach is followed for all database interaction across an application.</p> <p>I'm still trying to wrap my head around some MVC concepts but is there some reason why an edit action and an add action couldn't (or shouldn't) use the same view template, other than naming conventions?</p> <p>I see the routing is set up to expect the template names as shown in the tutorial but maybe I could have the view template to render the common form be called <code>process.phtml</code> and include that within <code>add.phtml</code> and <code>edit.phtml</code>. Is that a sensible approach is is there some reasons I should avoid that as a solution?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload