Should I combine my create and update controllers?

My controllers for updating and creating an object are pretty similar - they both do the same validation and form redirection. But they, of course, call different methods in the model. Should I combine them or leave them separate? Or should I just make a separate helper function to test?

Pros:

  • One controller instead of two
  • No duplication of verification code
  • The view (which I merged) can always point to the same controller

Minuses:

  • The merged controller is messy - there are several places where I have to check if it is being updated or created.
+3
source share
6

. , .. , , , .

, .

+2

, , ( ) ?

0

( ), ( ), , .

0

- .

Update . , , , .

, . . , . , .

0

, .

"blog.php", - , insert - .

:

blog/add
blog/update/1

.

, $data ['blog'] db. , .

0

Adding and updating are different methods for the same controller. Although I am a big fan of storing easy and smart code, after all, mixing material is more of a problem than a solution.

I suppose it depends on the complexity of the form you submit. For example, when you need to check for image replacement, it can be a pain.

MVC is about keeping things small and simple, right? Why mix it up?

0
source

Source: https://habr.com/ru/post/1777222/


All Articles