Answer the question
In order to leave comments, you need to log in
Interaction between controller and model?
Authorization function from controller:
// Авторизовать юзера с помощью электронной почты
public function maillogin()
{
$POST = $_POST;
$POST['mail'] = trim($POST['mail']);
$validate = new Validator();
if(!empty($_POST['mail']) && !empty($_POST['pwd']) && $validate->correctMail($_POST['mail']) === true){
// В модель ничего не передаётся т.к. она возьмёт данные из POST
$data = $this->userModel->{__FUNCTION__}();
if($data === 'WrongPassword'){
$view = new ErrorView();
$view->wrongPwd();
}
elseif($data === 'WrongLogin') {
$view = new ErrorView();
$view->wrongLogin();
}
} else {
$view = new ErrorView();
$view->noData();
}
}
if(password_verify($POST['pwd'], $pwd[0]['pwd'])){
$_SESSION['ok'] = 'Вы успешно авторизованы';
header("Location: {$_SERVER['HTTP_REFERER']}");
die();
}
maillogin()
exists both in the controller and in the model, is it normal, or is it better to do it, mailloginController()
and mailloginModel()
new ErrorView()
in advance, for example, in the same place where new Validator()
I can shorten the code below, and not write instantiation in each, if
but if everything goes ok, then it will be needed and it will be a waste of memory. What is the best way to do it in this case? die()
I don’t like it in the model, but I don’t know how to replace it, as is usually done in such cases?Answer the question
In order to leave comments, you need to log in
1. Normal. OOP was created for this, that a method with the same name can be in different classes, but work in its own way, if this is consistent with the general logic.
2. For good, the model should simply describe the data, in extreme cases, return the data sets associated with it, but not return instances of third-party classes
3. Not the case where you need to worry about wasting memory. You do not create 10,000 copies. But it could be done nicely
so that the errorView constructor returns a view by the name of the error, and the functions wrongLogin and wrongPwd would be private.
4) Why is there die at all?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question