Quan Nguyen
Quan Nguyen

Reputation: 560

Php concatenate a string into field generated by Yii2

I have the code to show the image (Yii2). $brand is an object, logo is a field of this object

<?= $form->field($brand, 'logo')->fileInput(['accept' => $acceptFileTypesInput]) ?>

After that, 'logo' will have value 'assets/uploads/logos/-4a47a0db6e.png' ==> wrong path

I want to concatenate Url::to('@web/') before the value of 'logo' ==> /app/backend/web/assets/uploads/logos/-4a47a0db6e.png

How can I do it?

Upvotes: 2

Views: 801

Answers (1)

Tony
Tony

Reputation: 5867

Try to pass value key into options array:

<?= $form->field($brand, 'logo')->fileInput(
    [
        'accept' => $acceptFileTypesInput, 
        'value' => Url::to('@web/') . $brand->logo
    ]
) ?>

Upvotes: 4

Related Questions