Hi, i tried to place an image on the navbar menu and I can not make it functional, here I put an example of my code, any suggestions,
$menuItems = ['label' => 'Opciones Usuario: ',
'items' => [
['label' => Html::img(BaseUrl::to('gravatar.com/avatar/<?=' . Yii::$app->user->identity->profile->gravatar_id . ' ?>?s=24', 'https')), 'url' => ['/user/settings/profile']],
['label' => 'Logout', 'url' => ['/user/security/logout'],'linkOptions' => ['data-method' => 'post']],
This part is very wrong:
BaseUrl::to('gravatar.com/avatar/<?=' . Yii::$app->user->identity->profile->gravatar_id . ' ?>?s=24', 'https')
The link is external, so you should construct it directly rather than using the URL helpers. Further, you can’t use PHP echo tags within a string like that.
I think you need something like this to generate the image:
$gravatarImageUrl = 'https://gravatar.com/avatar/'
// Then later:
You don’t need to separate them like that, but I think it makes it easier to follow.
ok perfect, but since I can add the image to the menu item label, display next to the text,
Solved my problem was not the image, you can include the option encodeLabels = false navbar widget