A
A
AlpineMilk2018-02-28 13:29:18
PHP
AlpineMilk, 2018-02-28 13:29:18

Code improvement. How to improve checks?

5a9683c2c6c99699877107.png
There is a page where user data is displayed. There are 2 avatar pictures and a background, I check for the presence of a path in the database, if there is a path, then it shows a picture; if not, then the default picture, but for each picture you have to do the same checks, and it looks terrible. How can this be improved?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-02-28
@webinar

We write a method that returns true or false and checks for the presence of any image, depending on the passed key. We write a getter that returns a url, in which the condition depends on the execution of the first method. And it's all in the user object. Then just$user->avatar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question