glossary literary terms M.H. Abrams, University of Pennsylvania, Philadelphia, 1955, 22 x 15 cm. .
Literary Terms : A Glossary of Literary Theory / by M. H. Abrams. New York : Harcourt Brace Jovanovich, 1956.
M. H. Abrams, University of Pennsylvania, Philadelphia, 1955, 22 x 15 cm. .Q:
Why do I have to return the database instead of returning $this in an Active Record find method?
I've seen this code from the MVC pattern many times, but I just don't understand why it is necessary. Why is there an explicit return $this instead of just return $this->get(...)?
public function findUser($email) {
if (!$this->validateEmail($email)) {
return false;
}
if (empty($this->attributes)) {
$this->create(...);
}
$query = $this->model->find('users', ['email' => $email]);
return $query? $query->first() : false;
}
A:
Because with your way of code the code you call doesn't have any reference to the class of the current object.
If you use $this->model->find(...) this will return a new model object with the previous data.
So with your way of code, if the email in the database doesn't match the input, the new model object has a empty email attribute. And the query builder class will return false because it's be359ba680
Related links:
Comentarios