A
A
Artyom2019-07-14 19:14:02
PHP
Artyom, 2019-07-14 19:14:02

Do I need to pass and process $_POST for the model?

Hello!
Since I recently started switching from a procedural to an OOP, I’m interested in the following moment: well, in the procedural we send $ _POST from the page with the form to a separate handler file and there we already have a reception, validation, writing to the database and a redirect, for example, back to form page.
But it's not quite clear how to do it CORRECTLY in oop?
Accept, validate in the controller, and then send the processed data to the model method for writing to the database?
Or ONLY accept and validate, and if successful, simply write data to the $_POST database in the model without transferring them from the controller to the model, because $_POST is superglobal?
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Suha, 2019-07-14
Ryzhenky @Artyom_Ryzhenky

It seems to me that you are confusing the concepts of oop and mvc. Well, in general, after the theory, try some kind of framework for example laravel, where the request is received by the router, sends it to the controller, and the controller calls the model that writes to the database

S
stepan-neretin7, 2019-07-14
@stepan-neretin7

You accept a post in the controller, validate and pull the function of writing to the database from the model, indicating in the arguments what you are changing and that's it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question