Problems showing image in the brandLabel of NavBar in Yii2

0

Well, something strange happens to me when I want to show images in the NavBar of the main menu, which is in the layout folder of the views

Initially I was using the basic template of Yii2, but then I realize that I needed to use frontend and backend, and I make the change for the advanced template.

For the menu bar of the application, I use a NavBar, in which I put an image in the 'brandLabel' property. In the basic template everything works fine, but in the advanced does not show me the image in the root of the site (the index of the home page), but if it shows in all other pages of the application.

Apparently it is some problems with the route, but I do not understand what happens

What I did was to pass everything I had in the basic template for the frontend, and in common I put the configurations (connection to the DB) that I will also need in the backend

The route of the image I put it like this: "../../web/img/sisleg60.png"

If I change the route and put it like this: "img / sisleg60.png"

then it happens the other way around, you can only see the image in the index, and not in the other pages

How can I solve this problem? What am I doing wrong?

Note: I had never worked with the advanced template

    
asked by José A. Cáceres 07.02.2018 в 23:15
source

1 answer

0

I hope this helps you, I'm getting the URL with Yii :: $ app-> getUrlManager () and I assign the base path with getBaseUrl (), the latter goes to the "web" directory, taking into account that your web folders are located "img (/img/logo.png ")", "css", "js", I'm occupying the advanced template, it's exactly the same in the frontend.

 <img class="navbar-brand"  src="<?= Yii::$app->getUrlManager()->getBaseUrl()?>/img/logo.png">
    
answered by 07.02.2018 / 23:31
source