A
A
Ainur1232018-04-23 17:10:27
Yii
Ainur123, 2018-04-23 17:10:27

How to display images on the main screen in Yii2?

How to display pictures on the main screen? Using the extension, costa-rico was able to display images in the article itself, but it is not possible to display images on the main screen. Here is how it was deduced in the article

<?php
            $mainImg=$product->getImage();
            //$mainFile=$product->getImage();
            $gallery=$product->getImages();
            //debug($mainFile=$product->getImage());
            ?>

<?= Html::img($mainImg->getUrl(),['alt'=>$product->name, 'height'=>350])?>

But with the same principle of displaying on the main page, it gives an error Call to a member function getImage() on a non-object

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2018-04-23
@webinar

I understand that you do not understand at all what you are doing and how everything works. This is normal for a beginner. But it means to go back and pull up what was missed. As I understand it, you need to finish learning php and stop using other people's solutions like "costa-rico" until you write your own and understand how it works. No other way.
Mistake

Call to a member function getImage() on a non-object

Says that you are accessing the getImage method but not on the object, as expected. It debugs in 2 minutes. But not blindly. According to your code, only call a fortune teller. The error usually specifies the file and line on which it occurred. What's stopping you from seeing what's there? And show us. Preferably with neighboring code, the whole method for example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question