Ich versuche ohne Erfolg, ein Bild in einem Navbar-Menü Item hinzuzufügen.Yii2: So fügen Sie ein Bild als Navbar-Menüeintrag hinzu
Es funktioniert gut in dem Brandlabel aber funktioniert nicht auf anoter Menüpunkt (Ich mag das angemeldeten Benutzer Bild in der Nähe seines Namen anzuzeigen)
ich mehrmals tryed aber scheint nicht daran, funktionieren Würde apreciate Ihre Hilfe bitte ...
Der Kodex ist folgendes:
<?php $this->beginBody() ?>
<div class="wrap">
<?php
NavBar::begin([
'brandLabel' => Html::img('@themes'.'/siteImages/Logo.jpg', ['alt'=>Yii::$app->name]),
'options' => [
'class' => 'navbar-default navbar-fixed-top',
],
]);
// display Login page to guests of the site
if (Yii::$app->user->isGuest) {
$menuItems[] = ['label' => Yii::t('app', 'Login'), 'url' => ['/site/login'],
'options' => [
'class' => 'navbar-right',
],];
}
else
{
// Show sales content to sales+ users
if (Yii::$app->user->can('useSalesContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Sales'),
// 'class' => "pull-left",
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'sales',
'class' => 'navbar-left',
],
];
// Show Admin content to manager+ users
if (Yii::$app->user->can('useAdminContent'))
{
$menuItems[] = ['label' => Yii::t('app', 'Administration'),
'url' => Yii::$app->homeUrl,
'linkOptions' => ['id' => 'admin'],
'options' => [
'class' => 'navbar-left',
],];
}
// display Logout to logged in users
if (!Yii::$app->user->isGuest) {
$menuItems[] =
[
'label' => Yii::t('app', 'Logout'). ' (' . Yii::$app->user-
>identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']
//****** This is where I want the user image to be shown ****//
];
}
}
// echo navbar with selected items
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => $menuItems,
]);
NavBar::end();
?>
<div class="container">
<?= Alert::widget() ?>
<?= $content ?>
</div>
(ENDBODY)>
Vielen Dank, es funktioniert gut! (nur geändert zu Html :: img anstelle von Html :: image –
Ja, ich sah es auch. Ich verwechselte es mit der guten alten Yii Syntax CHtml :: image(). Bitte akzeptieren Sie es als eine angenommene Antwort. –
@MichalYosef sollten Sie akzeptieren die Antwort von Maarten zur Verfügung stellen .. ..sehen, wie hier http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – scaisEdge