Hello,
I'm trying to create a very specific static function for my application. I have my Users model, and I have added the static method Users::getEmailById
so that I don't have to create an object if I'm simply trying to obtain the email of a random user.
At the moment, I don't know how to simply fetch a database value using models, so I am using this code to accomplish that task:
public static function getEmailById($user_id) {
$user = Users::findFirstById($user_id);
if(! empty($user)) {
return $user->email;
}
return null;
}
However, this is creating a Users object for basically no reason, because I won't be utilizing the object any further than grabbing the email value.
Is this some method of saying: Users model, give me the email of a user with an id value of $user_id
?
I know the actual performance impact of my current method is irrelevant, but I would like to accomplish my goals in the most efficient way possible.
Thanks!
Edit: Would \Phalcon\Db
be a better idea for this type of task?