Answer the question
In order to leave comments, you need to log in
How to generate html code in yii2 model?
There was a need to create html code in a model or controller, then pass it to the view and draw it there. That's how I imagine it to be, but it doesn't work. Is there such a possibility at all?
Model
public function getImage()
{
$str = '';
foreach ($this->file as $img) { // file - геттер связи с другой таблицей
$str = $str + Html::img(Url::to([$img->Image]), ['width'=>'100px']) + ' ';
// Image - атрибут, в котором храниться путь к файлу
}
return $str;
}
<?= DetailView::widget([
'model' => $model,
'attributes' => [
// other att
[
'label' => 'Картинки',
'value' => $model->image,
],
],
]); ?>
Answer the question
In order to leave comments, you need to log in
Works like this
Модель
public function getImage()
{
$str = '';
foreach ($this->file as $img) {
$str = $str . Html::img(Url::to([$img->Image]), ['width'=>'100px']) . ' ';
}
return $str;
}
<?= DetailView::widget([
'model' => $model,
'attributes' => [
// other attr
[
'label' => 'Image',
'format' => 'html',
'value' => $model->image,
],
],
]); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question