D
D
deadmemoras2016-08-07 01:01:18
PHP
deadmemoras, 2016-08-07 01:01:18

How to correctly implement sending $_POST data and returning an error?

In general, there is a small mvc, I write on it.
Now I am writing the registration, and there was a "thinking":
The register method accepts the entered data from the input - what should I do next? Well, that is, check for the correctness of the entered data and the emptiness, and if everything is normal, I pass the data to the reg method (model) and there I already do everything that is needed (adding to the database) or, it’s better to transfer the entered data to the model (immediately ) and there already check if there is an error - I return return false and check if(!Auth::reg($_POST['login']...) $this->error('Invalid data entered')
? also, what would be the best way to do the if($_POST['submit']) condition?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Greg Popov, 2016-08-07
@Gregpopov

Validation is performed at the level of the Model, since its data, validation and responsibility for them lies with the model.
The data needs to be secure, cut off extra spaces around the edges, and validate. Everything, record in a DB and a curtain.

D
DVamp1r3, 2016-08-07
@DVamp1r3

if ( ($model->load($app->request->post()) !== false)
something like this, for example, creates a new model with validation and other husks in yii.
for delimiting access to actions on the controller is responsible for the model, i.e. after checking the rights to the action, work with the model begins.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question