S
S
sdgs4s4 .2017-09-22 09:43:48
Yii
sdgs4s4 ., 2017-09-22 09:43:48

Yii2 -> getimage() -> how to remove no-image image if there is no product image?

Valar Morghulis!
I display "about the company" and in some places there is a picture, in some places there is not. How to correctly set the condition for this case (there is or is not a picture)

view (zhmyak)

<?php foreach($about as $about2): ?>
        <?php $mainImg = $about2->getImage();?>
    
              <?= $about2->content?>
            
              <?php if(!$mainImg->getUrl()): ?>
                      <?= Html::img($mainImg->getUrl('653x612'), ['alt' => $about2->name])?>
              <?php endif;?>
            
    <?php endforeach;?>


What would be the correct way to write the if condition in this case?
At the moment, I only have in my head to create a crutch, where I will mark the checkbox when adding, and get one or zero from the database according to the condition - if 1 - show the image, if 0 - do not show.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-09-22
@qonand

If I understand the question correctly, then
if( !empty($mainImg->getUrl()))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question