B
B
Boooom2018-09-05 03:42:29
Yii
Boooom, 2018-09-05 03:42:29

Yii2 - GridView - how to display an image?

Hello everyone, tell me how to display an image in a GridView
I use costa-rico (link to git in the comments)

array(
                'format' => 'image',
                'value'=>function($data) { return $data->imageurl; },

            ),

In the model
public function getImageurl()
    {
        $category = Category::find()->one();
        $img = $category->getImage();

        return $img->getUrl();
    }

I understand that with ->one() I get the same image. I don’t know how to pass a variable with an id by which images will be received, help me out
* don’t throw sticks, it’s completely green in yii

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2018-09-05
@boooom

$category = Category::find()->andWhere(['id'=>$this->category_id])->one();
if (!$category) {
 return null;
}
$img = $category->getImage()
return $img->getUrl();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question