vanhelvzla
(Wilmer Arambula)
November 25, 2014, 3:38pm
1
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']],
],
];
Best Regards,
Keith
(Kburton)
November 25, 2014, 4:12pm
2
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/'
. Yii::$app->user->identity->profile->gravatar_id
. '?s=24';
// Then later:
Html::img($gravatarImageUrl)
You don’t need to separate them like that, but I think it makes it easier to follow.
vanhelvzla
(Wilmer Arambula)
November 25, 2014, 5:07pm
3
ok perfect, but since I can add the image to the menu item label, display next to the text,
regards,
vanhelvzla
(Wilmer Arambula)
November 25, 2014, 5:28pm
4
Solved my problem was not the image, you can include the option encodeLabels = false navbar widget